Driver Code
let N = 3 , M = 3 , K = 4 ; let query = [ [ 0 , 0 ] , [ 1 , 1 ] , [ 1 , 0 ] , [ 1 , 2 ] ] ; let result = solve ( N , M , query ) ; for ( let i = 0 ; i < K ; i ++ ) document . write ( result [ i ] + " " ) ;