• + 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. */
    
        Scanner scanner = new Scanner(System.in);
    
        int size = scanner.nextInt();
    
        ArrayList<List> data = new ArrayList<>();
    
        scanner.nextLine();
        for(int i=0; i<size; i++){
            // int limit = scanner.nextInt();
            String str = scanner.nextLine();
            String[] arr =  str.split(" ");
            data.add(Arrays.asList(arr));
        }
    
        int searchSize = scanner.nextInt();
    
        scanner.nextLine();
        for(int i=0; i<searchSize; i++){
            String str = scanner.nextLine();
            String[] arr =  str.split(" ");
            int dataIndex = Integer.parseInt(arr[0]);
            int searchIndex = Integer.parseInt(arr[1]);
            List<String> fetch = data.get(dataIndex-1);
            if(fetch.size() > searchIndex){
                System.out.println(fetch.get(searchIndex));
            }else{ 
                System.out.println("ERROR!");
            }
        }
        scanner.close();
    }
    

    }