• + 0 comments
            ArrayList <ArrayList> matrix = new ArrayList<>();
            Scanner s = new Scanner(System.in);
            
            int lineCount = s.nextInt();
            //System.out.println("LineCount= " + lineCount);
            
            s.nextLine();
            
            for(int i=0; i<lineCount; i++){
                ArrayList tmpAL = new ArrayList<>();
                String[] stmp = s.nextLine().trim().split(" ");
                
                for(int j=0; j<stmp.length; j++){
                   tmpAL.add(stmp[j]);
                   //System.out.println("stmp " + stmp[j]);
                }
                
                matrix.add(tmpAL);
            }
            
            int queryCount = s.nextInt();
            //System.out.println("QC: " + queryCount);
            
            for(int i=0; i<queryCount; i++){
                int x = s.nextInt();
                int y = s.nextInt();
              
                //System.out.println(matrix.get(x-1).get(y));
                
                try{
                    System.out.println(matrix.get(x-1).get(y));
                } catch(Exception ex){
                    System.out.println("ERROR!");
                }
            }
            
            s.close();
        }