2017-02-16 23:51:56 -06:00
|
|
|
// Author: Rodney Shaghoulian
|
2018-07-27 16:45:56 -07:00
|
|
|
// Github: github.com/RodneyShag
|
|
|
|
|
// HackerRank: hackerrank.com/RodneyShag
|
2017-02-16 23:51:56 -06:00
|
|
|
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
public class Solution {
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
Scanner scan = new Scanner(System.in);
|
|
|
|
|
int n = scan.nextInt();
|
|
|
|
|
|
|
|
|
|
/* Save numbers in 2-D ArrayList */
|
2017-03-24 00:02:30 -05:00
|
|
|
ArrayList<ArrayList<Integer>> lists = new ArrayList<>();
|
2017-02-16 23:51:56 -06:00
|
|
|
for (int row = 0; row < n; row++) {
|
|
|
|
|
int d = scan.nextInt();
|
2017-03-24 00:02:30 -05:00
|
|
|
ArrayList<Integer> list = new ArrayList<>();
|
2017-02-16 23:51:56 -06:00
|
|
|
for (int col = 0; col < d; col++) {
|
2017-03-24 00:02:30 -05:00
|
|
|
list.add(scan.nextInt());
|
2017-02-16 23:51:56 -06:00
|
|
|
}
|
2017-03-24 00:02:30 -05:00
|
|
|
lists.add(list);
|
2017-02-16 23:51:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Answer the queries */
|
|
|
|
|
int q = scan.nextInt();
|
|
|
|
|
for (int i = 0; i < q; i++) {
|
|
|
|
|
int x = scan.nextInt();
|
|
|
|
|
int y = scan.nextInt();
|
2017-03-24 00:02:30 -05:00
|
|
|
ArrayList<Integer> list = lists.get(x-1);
|
|
|
|
|
if (y <= list.size()) {
|
|
|
|
|
System.out.println(list.get(y-1));
|
|
|
|
|
} else {
|
2017-02-16 23:51:56 -06:00
|
|
|
System.out.println("ERROR!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-24 00:02:30 -05:00
|
|
|
scan.close();
|
2017-02-16 23:51:56 -06:00
|
|
|
}
|
|
|
|
|
}
|