Input the queries in a 2D matrix
Scanner sc = new Scanner ( System . in ) ; for ( int i = 1 ; i <= m ; i ++ ) { q [ i ] [ 0 ] = sc . nextInt ( ) ; q [ i ] [ 1 ] = sc . nextInt ( ) ; q [ i ] [ 2 ] = sc . nextInt ( ) ; }