Stores the rank ( depth ) of each node
let rank = new Array ( n * m ) ; let grid = new Array ( n * m ) ; for ( let i = 0 ; i < ( n * m ) ; i ++ ) { rank [ i ] = 0 ; grid [ i ] = false ; } for ( let i = 0 ; i < query . length ; i ++ ) { let x = query [ i ] [ 0 ] ; let y = query [ i ] [ 1 ] ;