C. What Happens To Bashar's Laptop?
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

We all know how much it's annoying when a virus comes into your computer and start copy and paste folders until you run out of storage. However, there are antivirus which solve this problem.

But sometimes the virus comes to your computer in a human form. That's what happen to sad $$$\textit{Bashar}$$$ when he left his laptop with $$$\textit{Aswad}$$$.

To make you empathize with $$$\textit{Bashar}$$$, I will give you instructions to ruin your computer in $$$\textit{Aswad's}$$$ style and let you feel what $$$\textit{Bashar}$$$ has felt.

You are given the initial folders labeled from $$$1$$$ to $$$n$$$. For each folder you will be given the labels of folders inside it (of course there is no folder contains it self). The folder number $$$1$$$ is the Home folder.

You are given also $$$q$$$ queries. Each query consists of $$$k$$$ pairs $$$(u_i, v_i)$$$ where $$$(1 \le i \le k \le 3)$$$. And you have to do the following:

During the $$$i-th$$$ iteration $$$( 1 \leq i \leq k)$$$, You have to copy the folder $$$u_i$$$ (with all folders inside it) and paste it inside the folder $$$v_i$$$. (see the example for more clarification).

And since I want you to copy a copied folder, you have to assign labels to the newly pasted folders using the following rule: if the original folder is labeled as $$$u$$$, then the pasted node should be labeled as $$$u + n \times 2^{i-1} $$$ , where $$$i$$$ is the iteration number.

After you finish all the iterations, output the number of folders to see the terrible result.

Note that queries are independent.

Input

The first line contains an integer $$$n$$$ $$$(2 \le n \le 10^5)$$$.

The Next $$$n$$$ lines describe the contents of the folders:

the $$$i-th$$$ line from the $$$n$$$ lines start with an integer $$$s_i$$$ $$$(0 \le s_i \le 10^5)$$$ refers to the number of folders inside the $$$i-th$$$ folder, then followed by the labels of the folders.

Next line contains an integer $$$q$$$ $$$(1 \le q \le 10^5)$$$.

For the $$$i-th$$$ $$$(1 \le i \le q)$$$ query, first line contains an integer $$$k$$$ $$$(1 \le k \le 3)$$$.

The Next $$$k$$$ lines contain the described pairs in the statement. The $$$j-th$$$ line contains integers $$$u_j,$$$ $$$v_j$$$ $$$(1 \le u_j , v_j \le n \times 2^{j-1})$$$.

It is guaranteed that the input is valid.

Output

After performing the operations for each query, output a line contains the number of folders.

Example
Input
4
1 3
0
2 2 4
0
2
1
1 1
2
2 2
2 4
Output
8
7
Note

The initial folder structure is described by the first image.

After applying the first query the final folder will look like:

Note that queries are independent, so for the second query the folder structure will be as described in the first image.