Build query matrix
int [ ] temp = { 1 , 1 , 2 , 1 , 4 , 5 , 2 , 1 , 2 , 2 , 1 , 3 , 2 , 3 , 4 } ; int [ , ] query = new int [ 6 , 4 ] ; int j = 0 ; for ( int i = 1 ; i <= m ; i ++ ) { query [ i , 0 ] = temp [ j ++ ] ; query [ i , 1 ] = temp [ j ++ ] ; query [ i , 2 ] = temp [ j ++ ] ; }