Problem hidden
This problem was hidden by Editorial Board member probably because it has incorrect language version or invalid test data, or description of the problem is not clear.

EIUGWAR - Galaxy War

The X galaxy is facing its largest fight ever. The fight takes place across all regions with many of our and enemy warships, each identified by a code and strength. Determine the surviving ships in each region according to the following condition:

  • The ships will be assigned to specific regions to fight, and a list of ship codes will represent the fight in each region.
  • A stronger ship will defeat a weaker one. If two ships have equal strength, both will be destroyed.
  • Enemy and our ships located close to each other in the list will fight each other first according to the order of the list. For example: [1 2 -1] means that our ship number 2 will fight enemy ship number 1 first, and then based on the result of this fight, the next fight will be determined.

Input:

  • The first line is the number of warships N (2 ≤ N ≤ 3*105), and the number of regions M (1 ≤ M ≤ 105).
  • The next N lines each describe a warship: Ship code (positive for our ships, negative for enemy ships) (absolute value not exceeding 109) and ship strength (not exceeding 109).
  • The following M lines each describe a region: Region code K (not exceeding 109), number of warships in region K, and a list of K integers representing the fighting situation of K ships.

The testcase ensures that each ship only participates in one region.

Output:

  • For each region in the ascending order of identifier codes, an integer representing the winning side (1 is win, 2 is lose, 0 is a draw).

Sample

Input

Output

8 3

1 5

2 10

3 8

4 10

5 2

-1 5

-2 8

-3 5

1 3 1 2 -1

2 2 3 -2

3 3 4 5 -3

1 1

2 0

3 1


Added by:Ha Minh Ngoc
Date:2024-08-31
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:CSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG FSHARP GO JAVA JS-MONKEY NODEJS PHP PYTHON PYPY PYPY3 PYTHON3 RUBY SQLITE SWIFT VB.NET
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.