Storing input queries
ArrayList < ArrayList < Integer > > v = new ArrayList < > ( ) ; for ( int i = 0 ; i < q ; i ++ ) v . add ( new ArrayList < > ( ) ) ; v . get ( 0 ) . add ( 1 ) ; v . get ( 0 ) . add ( 5 ) ; v . get ( 0 ) . add ( 3 ) ; v . get ( 1 ) . add ( 4 ) ; v . get ( 1 ) . add ( 8 ) ; v . get ( 1 ) . add ( 7 ) ; v . get ( 2 ) . add ( 6 ) ; v . get ( 2 ) . add ( 9 ) ; v . get ( 2 ) . add ( 1 ) ;