Problem: A 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 ≤ 105) — 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 ui and vi (1 ≤ ui, vi ≤ 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 xi and yi (|xi|, |yi| ≤ 109) — the coordinates of the i-th vertex of the graph on the plane. 

The next line contains integer q (1 ≤ q ≤ 105) — the number of queries. Then follow q lines that describe the queries: the i-th line contains the sequence of space-separated integers ki, a1, a2, ..., aki (1 ≤ aj ≤ n; ki > 2), where ki is the cycle length in the i-th query, aj 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 105.

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

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5, inf = 2e9 + 1;
const double eps = 1e-9, pi = acos(-1);
int n, m, x, y, cs, ts;
double now_x;
int pos[N];
int q, qu[N], qs;
map<int, int> e[N];
double ans;
struct nod {
  double x, y;
  nod(double _x = 0, double _y = 0) {
    x = _x;
    y = _y;
  }
  nod operator-(const nod &b) { return nod(x - b.x, y - b.y); }
  nod operator*(const nod &b) {
    return nod(x * b.x - y * b.y, x * b.y + y * b.x);
  }
} a[N], ang = {cos(pi * 0.542), sin(pi * 0.542)};
struct nod2 {
  int x, y;
} b[N];
struct node {
  int op, i;
  double x;
  int sgn;
} c[N * 3];
struct splay {
  int f, s[2], su, ad, si, va;
  nod a, b;
  double val() {
    return (double)(now_x - a.x) / (b.x - a.x) * (b.y - a.y) + a.y;
  }
} t[N];
bool cmp(node a, node b) { return a.x < b.x || a.x == b.x && a.op < b.op; }
double cross(nod a, nod b) { return a.x * b.y - a.y * b.x; }
int d[N], ds;
void ro(int x) {
  int y = t[x].f, z = (x == t[t[x].f].s[1]);
  t[y].s[z] = t[x].s[!z];
  t[t[y].s[z]].f = y;
  t[x].f = t[y].f;
  t[t[y].f].s[(y == t[t[y].f].s[1])] = x;
  t[x].s[!z] = y;
  t[y].f = x;
  (t[y].si = t[y].va + t[t[y].s[0]].si + t[t[y].s[1]].si);
}
void add(int v, int ad) {
  t[v].ad += ad;
  t[v].su += ad;
}
void dw(int v) {
  if (t[v].ad) {
    if (t[v].s[0]) add(t[v].s[0], t[v].ad);
    if (t[v].s[1]) add(t[v].s[1], t[v].ad);
    t[v].ad = 0;
  }
}
void cl(int x) {
  for (ds = 0; x; x = t[x].f) d[++ds] = x;
  for (; ds; --ds) dw(d[ds]);
}
void sp(int x, int ff) {
  for (cl(x); t[x].f != ff; ro(x))
    if (t[t[x].f].f != ff)
      (x == t[t[x].f].s[1]) == (t[x].f == t[t[t[x].f].f].s[1]) ? ro(t[x].f)
                                                               : ro(x);
  (t[x].si = t[x].va + t[t[x].s[0]].si + t[t[x].s[1]].si);
}
int find(nod x) {
  int wz = 0;
  for (int v = t[0].s[1]; v;) {
    if (cross(t[v].b - t[v].a, x - t[v].a) > eps) {
      wz = v;
      v = t[v].s[1];
    } else {
      v = t[v].s[0];
    }
  }
  return wz;
}
int find2(splay x) {
  int wz = 0;
  for (int v = t[0].s[1]; v;) {
    if (t[v].val() < x.val()) {
      wz = v;
      v = t[v].s[1];
    } else {
      v = t[v].s[0];
    }
  }
  return wz;
}
void clear(int v) { t[v].s[0] = t[v].s[1] = t[v].ad = t[v].f = 0; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, _e = m; i <= _e; ++i) {
    scanf("%d%d", &x, &y);
    b[i] = (nod2){x, y};
  }
  for (int i = 1, _e = n; i <= _e; ++i) {
    scanf("%d%d", &x, &y);
    a[i] = nod(x, y) * ang;
    c[++cs] = (node){1, i, a[i].x};
  }
  for (int i = 1, _e = m; i <= _e; ++i) {
    if (a[b[i].x].x > a[b[i].y].x) swap(b[i].x, b[i].y);
    c[++cs] = (node){3, i, a[b[i].x].x};
    c[++cs] = (node){2, i, a[b[i].y].x};
  }
  sort(c + 1, c + cs + 1, cmp);
  c[cs + 1].x = 1e9 + 5;
  ts = 2;
  t[1].a = nod(-inf, -inf);
  t[1].b = nod(inf, -inf);
  t[2].a = nod(-inf, inf);
  t[2].b = nod(inf, inf);
  (t[1].f = 0, t[0].s[1] = 1);
  (t[2].f = 1, t[1].s[1] = 2);
  for (int i = 1, _e = cs; i <= _e; ++i) {
    int j = i;
    for (; (c[j].x - c[i].x > 0 ? c[j].x - c[i].x : -(c[j].x - c[i].x)) < eps;)
      ++j;
    --j;
    now_x = (c[i].x + c[j + 1].x) / 2;
    for (int k = i, _e = j; k <= _e; ++k) {
      int z = c[k].i;
      if (c[k].op == 1) {
        x = find(a[z]);
        sp(x, 0);
        add(t[x].s[1], 1);
      } else if (c[k].op == 3) {
        pos[z] = ++ts;
        t[ts].a = a[b[z].x];
        t[ts].b = a[b[z].y];
        x = find2(t[ts]);
        sp(x, 0);
        for (y = t[x].s[1]; t[y].s[0]; y = t[y].s[0])
          ;
        sp(y, x);
        (t[ts].f = y, t[y].s[0] = ts);
      } else {
        sp(pos[z], 0);
        x = b[z].x;
        y = b[z].y;
        e[x][y] = t[pos[z]].su;
        e[y][x] = -t[pos[z]].su;
        x = pos[z];
        for (y = t[x].s[1]; t[y].s[0]; y = t[y].s[0])
          ;
        sp(y, x);
        (t[y].f = 0, t[0].s[1] = y);
        (t[t[x].s[0]].f = y, t[y].s[0] = t[x].s[0]);
      }
    }
    i = j;
  }
  scanf("%d", &q);
  for (int o = 1, _e = q; o <= _e; ++o) {
    scanf("%d", &qs);
    for (int i = 1, _e = qs; i <= _e; ++i) scanf("%d", &qu[i]);
    qu[qs + 1] = qu[1];
    int ans = 0;
    for (int i = 1, _e = qs; i <= _e; ++i) ans += e[qu[i]][qu[i + 1]];
    ts = 2;
    clear(1);
    clear(2);
    (t[1].f = 0, t[0].s[1] = 1);
    (t[2].f = 1, t[1].s[1] = 2);
    cs = 0;
    for (int i = 1, _e = qs; i <= _e; ++i)
      c[++cs] = (node){1, qu[i], a[qu[i]].x};
    for (int i = 1, _e = qs; i <= _e; ++i) {
      int sgn = 1;
      x = qu[i];
      y = qu[i + 1];
      if (a[x].x > a[y].x) swap(x, y), sgn = -1;
      b[i].x = x;
      b[i].y = y;
      c[++cs] = (node){3, i, a[x].x, sgn};
      c[++cs] = (node){2, i, a[y].x, sgn};
    }
    sort(c + 1, c + cs + 1, cmp);
    c[cs + 1].x = 1e9 + 5;
    for (int i = 1, _e = cs; i <= _e; ++i) {
      int j = i;
      for (;
           (c[j].x - c[i].x > 0 ? c[j].x - c[i].x : -(c[j].x - c[i].x)) < eps;)
        ++j;
      --j;
      now_x = (c[i].x + c[j + 1].x) / 2;
      for (int k = i, _e = j; k <= _e; ++k) {
        int z = c[k].i;
        if (c[k].op == 1) {
          x = find(a[z]);
          sp(x, 0);
          ans -= t[t[x].s[1]].si;
        } else if (c[k].op == 3) {
          pos[z] = ++ts;
          clear(ts);
          t[ts].a = a[b[z].x];
          t[ts].b = a[b[z].y];
          x = find2(t[ts]);
          sp(x, 0);
          for (y = t[x].s[1]; t[y].s[0]; y = t[y].s[0])
            ;
          sp(y, x);
          t[ts].va = c[k].sgn;
          (t[ts].f = y, t[y].s[0] = ts);
          (t[ts].si = t[ts].va + t[t[ts].s[0]].si + t[t[ts].s[1]].si);
          (t[y].si = t[y].va + t[t[y].s[0]].si + t[t[y].s[1]].si);
        } else {
          sp(pos[z], 0);
          x = pos[z];
          for (y = t[x].s[1]; t[y].s[0]; y = t[y].s[0])
            ;
          sp(y, x);
          (t[y].f = 0, t[0].s[1] = y);
          (t[t[x].s[0]].f = y, t[y].s[0] = t[x].s[0]);
          (t[y].si = t[y].va + t[t[y].s[0]].si + t[t[y].s[1]].si);
        }
      }
      i = j;
    }
    printf("%d\n", (ans > 0 ? ans : -ans) + qs);
  }
}