How to take input

how to take Input as First line of input contains T denoting number of testcases. For each test case there will be two space seperated positive integers M and N in java

you need a loop here as you need T pair of inputs.
it will be like:
Scanner scn = new Scanner(System.in);
int T = scn.nextInt();
while (T > 0)
{ int M = scn.nextInt();
int N = scn.nextInt();
//do your stuff with M and N
T–;
}

Thanks.