Given two integers , we define the pair to be a subpair of a set if both and are in .
Given sets, your task is to answer queries of the following form: given two integers and , how many of the sets is a subpair of?
Input Specification
The input begins with a single integer , the number of sets.
The next lines each describe one of the sets. Each line begins with an integer and is followed by numbers , the elements of the set. The numbers in each set are guaranteed to be unique. The total number of elements across all sets will not exceed .
The next line contains a single integer , the number of queries to answer. The next lines each contain the pair of different integers to query.
For 30% of points, .
Output Specification
Output a single integer: the sum of the answers for each query.
Sample Input 1
3
2 1 3
2 1 2
3 1 2 3
4
1 2
1 3
2 3
4 5
Sample Output 1
5
Comments