• + 0 comments
    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 sc = new Scanner(System.in);
            
            int row = Integer.parseInt(sc.next());
            sc.nextLine();
            
            List<List<Integer>> input = IntStream.range(0, row)
                .mapToObj(unused -> {
                return Arrays.stream(sc.nextLine().trim().split(" "))
                        .skip(1)
                        .map(Integer::parseInt)
                        .collect(Collectors.toList());
                })
                .collect(Collectors.toList());  
            
            row = sc.nextInt();
            
            IntStream.range(0, row)
            .forEach(unused -> {
                int x = sc.nextInt() - 1;
                int y = sc.nextInt() - 1;
                
                if (x < input.size() && y < input.get(x).size())
                    System.out.println(input.get(x).get(y));
                else
                    System.out.println("ERROR!");
            });
            
            sc.close();
        }