Codeforces Round 138 (Div. 1) |
---|

Finished |

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

flows

geometry

graphs

*3000

No tag edit access

The problem statement has recently been changed. View the changes.

×
E. Planar Graph

time limit per test

1 secondmemory limit per test

256 megabytesinput

standard inputoutput

standard outputA graph is called planar, if it can be drawn in such a way that its edges intersect only at their vertexes.

An articulation point is such a vertex of an undirected graph, that when removed increases the number of connected components of the graph.

A bridge is such an edge of an undirected graph, that when removed increases the number of connected components of the graph.

You've got a connected undirected planar graph consisting of *n* vertexes, numbered from 1 to *n*, drawn on the plane. The graph has no bridges, articulation points, loops and multiple edges. You are also given *q* queries. Each query is a cycle in the graph. The query response is the number of graph vertexes, which (if you draw a graph and the cycle on the plane) are located either inside the cycle, or on it. Write a program that, given the graph and the queries, will answer each query.

Input

The first line contains two space-separated integers *n* and *m* (3 ≤ *n*, *m* ≤ 10^{5}) — the number of vertexes and edges of the graph. Next *m* lines contain the edges of the graph: the *i*-th line contains two space-separated integers *u*_{i} and *v*_{i} (1 ≤ *u*_{i}, *v*_{i} ≤ *n*) — the numbers of vertexes, connecting the *i*-th edge. The next *n* lines contain the positions of the planar graph vertexes on the plane: the *i*-th line contains a pair of space-separated integers *x*_{i} and *y*_{i} (|*x*_{i}|, |*y*_{i}| ≤ 10^{9}) — the coordinates of the *i*-th vertex of the graph on the plane.

The next line contains integer *q* (1 ≤ *q* ≤ 10^{5}) — the number of queries. Then follow *q* lines that describe the queries: the *i*-th line contains the sequence of space-separated integers *k*_{i}, *a*_{1}, *a*_{2}, ..., *a*_{ki} (1 ≤ *a*_{j} ≤ *n*; *k*_{i} > 2), where *k*_{i} is the cycle length in the *i*-th query, *a*_{j} are numbers of the vertexes that form a cycle. The numbers of vertexes in the cycle are given in the clockwise or counterclockwise order. The given cycles are simple, that is they cannot go through a graph vertex more than once. The total length of all cycles in all queries does not exceed 10^{5}.

It is guaranteed that the given graph contains no bridges, articulation points, loops and multiple edges. It is guaranteed that the edge segments can have common points only at the graph's vertexes.

Output

For each query print a single integer — the number of vertexes inside the cycle or on it. Print the answers in the order, in which the queries follow in the input. Separate the numbers by spaces.

Examples

Input

3 3

1 2

2 3

3 1

0 0

1 0

0 1

1

3 1 2 3

Output

3

Input

5 8

1 2

2 3

3 4

4 1

1 5

2 5

3 5

4 5

0 0

2 0

2 2

0 2

1 1

1

4 1 2 3 4

Output

5

Input

4 5

1 2

2 3

3 4

4 1

2 4

0 0

1 0

1 1

0 1

3

3 1 2 4

3 4 2 3

4 1 2 3 4

Output

3

3

4

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/14/2024 20:11:11 (h2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|