All submissions for this problem are available.$Striver$ wants to strive hard in order to reach his goals, hence asks his mentor to give him a question for which he has to strive hard. The mentor gives $Striver$ a $N$ X $N$ matrix consisting of lowercase characters ($'a'$ to $'z'$) and $Q$ queries. Every query consists of $X$ and $Y$. From any position in the matrix, one can either move towards the right or towards down. He asks striver to write down all the paths from $(1, 1)$ to $(X, Y)$ and find out which string has the maximum number of character $'a'$ in it and answer him the number of characters which are not 'a' in that string. Striver wants to strive hard but also wants to impress his mentor. He asks for your help to answer $Q$ queries given by his mentor as fast as he can so that he can impress his mentor also. Can you help him to answer the Q queries? ###Input: - First line will contain $T$, number of test cases. Then the test cases follow. - First line of every test case contains a number $N$ and $Q$ which denotes the dimensions of the matrix and number of queries respectively. - N lines follow, which contains N numbers each denoting the elements of the matrix. - Q line follow, every line contains X and Y. ###Output: For every test case, print a single integer which prints the answer to mentor's every query. ###Constraints - $1 \leq T \leq 10$ - $1 \leq N \leq 10^3$ - $1 \leq Q \leq 10^5$ - $1 \leq X, Y \leq N$ ###Sample Input: 1 3 2 a b a a c d b a b 1 3 3 3 ###Sample Output: 1 2 ###EXPLANATION: Query-1: There is only one path from (1,1) to (1,3) i.e.,"aba" and the number of characters which are not 'a' is 1. Query-2: The path which has the maximum number of 'a' in it is "aabab", hence non 'a' characters are 2.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS|
Fetching successful submissions