• + 0 comments

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        List<List<Integer>> listOfArray = new ArrayList<>();
        Scanner s= new Scanner(System.in);
        int n =s.nextInt();
        for(int i=0;i<n;i++){
            int d=s.nextInt();
            List<Integer> listf = new ArrayList<Integer>() ;
            for(int j=0;j<d;j++){
            listf.add(s.nextInt());
            }
            listOfArray.add(listf);
        }
       // System.out.println(listOfArray);
       int q =s.nextInt();
       for(int i=0;i<q;i++){
         int x= s.nextInt();
         int y =s.nextInt();
         try{
        System.out.println( listOfArray.get(x-1).get(y-1));
         }
         catch(Exception ex){
             System.out.println("ERROR!");
         }
       }
            s.close();
    
    
    }
    

    }