#B3665. Data Queries XOR

    ID: 11324 Type: Default 1000ms 256MiB

Data Queries XOR

Data Queries XOR

You are given \(n\) datasets. The \(i\)-th dataset contains \(s_i\) numbers: \(a_{i,1}, a_{i,2}, \dots, a_{i,s_i}\).

Then, you are given \(q\) queries. Each query asks for the value \(a_{x,y}\) from the \(x\)-th dataset and the \(y\)-th number in it.

Your task is to compute the bitwise XOR (denoted by the '^' operator in C++) of all the answers to these queries.

Note: Bitwise XOR is the operator that computes the XOR of two integers, e.g., in C++ using the '^' operator. You can refer to the hint section for a code snippet that computes the XOR of several numbers.

inputFormat

The first line contains a single integer \(n\) indicating the number of datasets.

For each \(i\) from 1 to \(n\), the first integer of the line is \(s_i\) (the number of elements in the \(i\)-th dataset) followed by \(s_i\) integers: \(a_{i,1}, a_{i,2}, \dots, a_{i,s_i}\).

The next line contains a single integer \(q\) representing the number of queries.

Each of the following \(q\) lines contains two integers \(x\) and \(y\) representing a query that asks for \(a_{x,y}\).

outputFormat

Output a single integer, which is the bitwise XOR of all the query answers.

sample

2
3 1 2 3
2 4 5
3
1 2
2 1
1 3
5