beecrowd | 2222

Playing with Sets

By Gabriel Duarte, UNIFESO BR Brazil

Timelimit: 1

Dabriel is a fissured boy for mathematics, today he learned at his school some set operations.
After spending the afternoon playing with some sets that he has, it's time to solve the homework, but he is already very tired and afraid to make some mistakes, asked for your help.

Dabriel wants a computer program that given N sets and the elements of each set, it can perform some operations, they are:

1 X Y: Returns the number of distinct elements in the intersection of the set X and Y.

2 X Y: RReturns the number of distinct elements in the union of the set X and Y.

Input

The input consists of several test cases. Each test case starts with an integer N (1 ≤ N ≤ 10⁴), representing the number of sets that Dabriel has. The next N lines begin with a integer Mi (1 ≤ Mi ≤ 60), indicating the total number of elements that set i have, then follows Mi integers Xij (1 ≤ Xij ≤ 60), representing the value of each element. The next line has a integer Q (1 ≤ Q ≤ 10⁶), representing how many operations Dabriel want to perform. In the next Q lines have the description of an operation. The input ends with N = 0 and should not be processed.

Output

For each operation, your program should print the number of elements, as explained in the description.

Input Samples Output Samples

1
4
1 1
2 1 5
3 2 4 6
4 1 3 5 7
5
1 1 2
1 1 4
2 1 4
2 3 4
1 2 4

1
1
4
7
2