Given queries
ArrayList < Pair > Q = new ArrayList < Pair > ( ) ; Pair pair = new Pair ( 2 , 7 ) ; Q . add ( pair ) ; Pair pair2 = new Pair ( 10 , 25 ) ; Q . add ( pair2 ) ; precompute ( ) ; for ( int i = 0 ; i < Q . size ( ) ; i ++ ) {