Vasya and sets#4509

Vasya and sets

2 seconds
128 megabytes
Very easy

Vasya likes to formalize everything. For example, Vasya sees a lot of vegetables in his grandmother's garden, and a lot of toys his younger brother has. And what will happen if you try to combine or to intersect 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 (1 \le n \le 20). Then sets are given in the following format:

  • First line contains number (1 \le t \le 10^6) - the number of integers in the next line.

  • Second line contains integers x_i (1 \le x_i \le 10^6) - the elements of the set.

Next line contains the number of queries (1 \le m \le 100). Each of the next lines contains the queries of two types:

  • INTERSECTION , where 1 \le a, b \le n

  • UNION , where 1 \le a, b \le n

Output

Print for each query:

  1. For the query of the first type the number of elements in the intersection of sets and .

  2. For the query of the second type the number of elements in the union of sets and .

Examples

Example 1

Loading
Loading