Vasya and sets
Vasya likes to formalize everything. For example, Vasya sees a lot of vegetables in his grandmother's garden, and a lot of toys in his younger brother. And what will happen if you try to combine or to intersect n sets? Large and different sets - up to a million elements (inclusive)!
Since Vasya dreams to become a mathematician, he decided to start his research with the study of simpler sets, namely sets of integers.
Input
First line contains the number of different sets n (1 ≤ n ≤ 20). Then n sets given in the next format:
First line contains number t (1 ≤ t ≤
10^6
) - the number of integers in the next line.Second line contains t integers
x[i]
(1 ≤x[i]
≤10^6
) - the elements of the set.
Next line contains the number of queries m (1 ≤ m ≤ 100). Each of the next m lines contains the queries of two types:
INTERSECTION a b, where 1 ≤ a, b ≤ n
UNION a b, where 1 ≤ a, b ≤ n
Output
Print for each query:
For the query of the first type the number of elements in the intersection of sets a and b.
For the query of the second type the number of elements in the union of sets a and b.