@@ -0,0 +1,1853 @@
+import java.io.*;%0Aimport java.util.*;%0A%0Apublic class Solution %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A        Scanner scanner = new Scanner(System.in);%0A        List%3CList%3CInteger%3E%3E numbers = getNumbersFromInput(scanner);%0A%0A        // It may be more appropriate to store queries as a tuple%0A        List%3CList%3CInteger%3E%3E queries = getQueriesFromInput(scanner);%0A%0A        executeQueries(numbers, queries);%0A    %7D%0A%0A    private static void executeQueries(List%3CList%3CInteger%3E%3E numbers, List%3CList%3CInteger%3E%3E queries) %7B%0A        for (List%3CInteger%3E query : queries) %7B%0A            Integer x = query.get(0);%0A            Integer y = query.get(1);%0A%0A            try %7B%0A                System.out.println(numbers.get(x - 1).get(y - 1));%0A            %7D catch (IndexOutOfBoundsException e)%7B%0A                System.out.println(%22ERROR!%22);%0A            %7D%0A        %7D%0A    %7D%0A%0A    private static List%3CList%3CInteger%3E%3E getNumbersFromInput(Scanner scanner) %7B%0A        Integer numberOfLines = scanner.nextInt();%0A        List%3CList%3CInteger%3E%3E lines = new ArrayList%3C%3E();%0A%0A        for (int i = 0; i %3C numberOfLines; i++) %7B%0A            Integer numberOfElements = scanner.nextInt();%0A            List%3CInteger%3E numbers = new ArrayList%3CInteger%3E();%0A            for (int j = 0; j %3C numberOfElements; j++) %7B%0A                numbers.add(scanner.nextInt());%0A            %7D%0A            lines.add(numbers);%0A        %7D%0A%0A        return lines;%0A    %7D%0A%0A    private static List%3CList%3CInteger%3E%3E getQueriesFromInput(Scanner scanner) %7B%0A        Integer numberOfQueries = scanner.nextInt();%0A        List%3CList%3CInteger%3E%3E queries = new ArrayList%3C%3E();%0A%0A        for (int i = 0; i %3C numberOfQueries; i++) %7B%0A            List%3CInteger%3E query = new ArrayList%3CInteger%3E();%0A            query.add(scanner.nextInt());%0A            query.add(scanner.nextInt());%0A            queries.add(query);%0A        %7D%0A%0A        return queries;%0A    %7D%0A%7D%0A

Solve arraylist