Олимпиадный тренинг

Задача 38788. Object properties - 2


Задача

Темы: Словари
There are n objects in Vasya's storage, numbered from 1 to n, each of which has a certain number of properties (possibly none). Each property is represented as a natural number from 1 to 109.
After analyzing the structure of his storage, Vasya decided that it should support two operations:
 -  Removing obsolete property c. When a property is deleted, it is deleted from all the objects it belongs to. If the specified property does not exist, nothing needs to be done.
 -  Find the number of properties removed from an object r
Vasya really needs to implement this functionality, and he turned to you for help. Help him - write a program that will support both operations that Vasya needs.

Input
The first line of the input file contains the number n - the number of objects in Vasya's storage (1 <= n <= 105). The i-th of the next n lines contains the description of the properties of the object with number i: first, the number ki is given - the number of properties of the i-th object, and then, space-separated, ki< /sub> numbers pi,j - properties of the i-th object (0 <= ki <= 100, 1 <= pi,j <= 109).
All objects are numbered from 1 to n in the order presented in the input. It is guaranteed that the total number of properties of all objects does not exceed 105. It is also guaranteed that for each i all pi,j are distinct.
Line n + 2 contains number q - the number of requests to Vasya's storage (1 <= q <= 105).
The j-th of the following q lines contains information about the j-th request:
-c if you want to remove obsolete property c from storage (1 <= c <= 109);
? r if you want to find the number of remaining properties of the object with number r.

Imprint
For all requests to find the number of remaining properties of the object, on separate lines, in the order they appear for each request, print this number.
 
Examples
# Input Output
1 2
3 1 2 4
3 2 3 5
12
- 1
? 1
? 2
- 2
? 1
? 2
- 5
? 1
? 2
- 6
? 1
? 2
1
0
2
1
2
2
2
2


Remark
Only the first object has property 1, so after removing it, the first object has 1 property removed, while the second still has 0.
Property 2 is on both objects, so it is removed from both objects, the first object now has 2 properties removed, and the second one has 1.
Only the second object has property 5, so after removing it, both objects have 2 properties removed.
None of the objects have property 6, so deleting it does not change the number of properties removed from objects.