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