#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int **arr, arrqtd, queries;
cin >> arrqtd >> queries;
arr = (int **) malloc(sizeof(int*)*arrqtd);
for (int i = 0; i < arrqtd;i++){
int size;
cin >> size;
arr[i] = (int *) malloc(sizeof(int)*size);
for(int j = 0; j < size;j++){
int value;
cin >> value;
arr[i][j] = value;
}
}
for (int i = 0; i < queries;i++){
int row,col;
cin >> row >> col;
cout << arr[row][col] << endl;
}
return 0;
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKCmludCBtYWluKCkgewogICAgaW50ICoqYXJyLCBhcnJxdGQsIHF1ZXJpZXM7CgogICAgY2luID4+IGFycnF0ZCA+PiBxdWVyaWVzOwoKICAgIGFyciA9IChpbnQgKiopIG1hbGxvYyhzaXplb2YoaW50KikqYXJycXRkKTsgIAogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBhcnJxdGQ7aSsrKXsKICAgICAgICBpbnQgc2l6ZTsKCiAgICAgICAgY2luID4+IHNpemU7CiAgICAgICAgYXJyW2ldID0gKGludCAqKSBtYWxsb2Moc2l6ZW9mKGludCkqc2l6ZSk7CgogICAgICAgIGZvcihpbnQgaiA9IDA7IGogPCBzaXplO2orKyl7CiAgICAgICAgICAgIGludCB2YWx1ZTsKICAgICAgICAgICAgY2luID4+IHZhbHVlOwogICAgICAgICAgICBhcnJbaV1bal0gPSB2YWx1ZTsKICAgICAgICB9CiAgICB9CgogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBxdWVyaWVzO2krKyl7CiAgICAgICAgaW50IHJvdyxjb2w7CiAgICAgICAgY2luID4+IHJvdyA+PiBjb2w7CiAgICAgICAgY291dCA8PCBhcnJbcm93XVtjb2xdIDw8IGVuZGw7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==
MTAgMTAKMyA5MTYxMzUgMjcyMTg4IDc5NDk2MwozIDE3ODk5NyA1MDI0NjggNjcxMjUxCjEgMTIyMjY2CjMgMjIzNTExIDk5NjA0MyA5OTAxMDQKMyAzMTk2OTQgMzM1MjA4IDIwMDc4OQoyIDg2NzgwOSAyNzM3OTMKMSA5MjUzNTgKMSA3MTE0MAoxIDg2MjIzOAoxIDk5NDMwOQo2IDAKNSAwCjUgMAo3IDAKNSAwCjYgMAozIDIKMyAxCjAgMAo5IDAK
10 10
3 916135 272188 794963
3 178997 502468 671251
1 122266
3 223511 996043 990104
3 319694 335208 200789
2 867809 273793
1 925358
1 71140
1 862238
1 994309
6 0
5 0
5 0
7 0
5 0
6 0
3 2
3 1
0 0
9 0