87_E. Mogohu-Rea Idol

A long time ago somewhere in the depths of America existed a powerful tribe governed by the great leader Pinnie-the-Wooh. Once the tribe conquered three Maya cities. Pinnie-the-Wooh grew concerned: there had to be some control over the conquered territories. That's why he appealed to the priests of the supreme god Mogohu-Rea for help.

The priests conveyed the god's will to him: to control these three cities he should put an idol to Mogohu-Rea — that will create a religious field over the cities. However, the idol is so powerful that it can easily drive the people around it mad unless it is balanced by exactly three sacrifice altars, placed one in each city. To balance the idol the altars should be placed so that the center of mass of the system of these three points coincided with the idol. When counting the center of mass consider that all the altars have the same mass.

Now Pinnie-the-Wooh is thinking where to put the idol. He has a list of hills, that are suitable to put an idol there. Help him to identify on which of them you can put an idol without risking to fry off the brains of the cities' population with the religious field.

Each city has a shape of a convex polygon such that no three vertexes lie on a straight line. The cities can intersect. Each altar should be attached to the city through a special ceremony, besides, it must be situated on the city's territory (possibly at the border). Thus, there may be several altars on a city's territory, but exactly one of them will be attached to the city. The altars, the idol and the hills are points on the plane, some of them may coincide.

The hills are taken into consideration independently from each other, the altars' location for different hills may also be different.

Input

First follow descriptions of the three cities, divided by empty lines. The descriptions are in the following format:

The first line contains an integer n, which represent the number of the polygon's vertexes (3 ≤ n ≤ 5·104). Next n lines contain two integers xi, yi each, they are the coordinates of the polygon's i-th vertex in the counterclockwise order.

After the cities' description follows the integer m (1 ≤ m ≤ 105), which represents the number of hills. Next m lines each contain two integers xj, yj, they are the coordinates of the j-th hill.

All the coordinates in the input data do not exceed 5·108 in the absolute value.

Output

For each hill print on a single line "YES" (without the quotes) or "NO" (without the quotes), depending on whether the three sacrifice altars can be put to balance the idol or not.

Examples

Input

3
0 0
1 0
1 1

4
8 8
5 5
6 4
8 4

3
-1 -1
-3 -1
-2 -2

5
0 0
2 1
7 1
1 1
5 3


Output

NO
YES
NO
YES
NO

Note

For the hill at (2, 1) the altars can be placed at the points (1, 0), (7, 5), ( - 2, - 2), for the hill at (1, 1) — at the points (0, 0), (6, 4), ( - 3, - 1). Many other groups of three points can do the trick. There are no suitable points for other hills.

Example input:
3
0 0
1 0
1 1

4
8 8
5 5
6 4
8 4

3
-1 -1
-3 -1
-2 -2

5
0 0
2 1
7 1
1 1
5 3


Example output:
NO
YES
NO
YES
NO


Tags: geometry
Difficulty rating: 2600

Solution:
#include <bits/stdc++.h>
using namespace std;
int const N = 50000;
struct P {
  long long x, y;
  P() : x(0), y(0) {}
  P(long long a, long long b) : x(a), y(b) {}
  void sc() { scanf("%lld%lld", &x, &y); }
  P operator+(P const &o) const { return P(x + o.x, y + o.y); }
  P operator-(P const &o) const { return P(x - o.x, y - o.y); }
  P operator*(int s) const { return P(x * s, y * s); }
  double ang() const { return atan2(y, x); }
  bool operator<(P const &o) const { return ang() < o.ang(); }
  long long operator|(P const &o) const { return x * o.y - y * o.x; }
  bool operator==(P const &o) const { return (*this | o) == 0; }
} p[N], b;
vector<P> h;
void sc() {
  int n, l = h.size(), mn = 0;
  scanf("%d", &n);
  for (int i = 0; i < (int)(n); ++i) p[i].sc();
  for (int i = 1; i < (int)(n); ++i)
    if (p[i].y > p[mn].y || p[i].y == p[mn].y && p[i].x < p[mn].x) mn = i;
  for (int i = mn; i < (int)(n); ++i) h.push_back(p[i]);
  for (int i = 0; i < (int)(mn); ++i) h.push_back(p[i]);
  P t = h[l];
  b = b + t;
  for (int i = l; i < (int)(h.size() - 1); ++i) h[i] = h[i + 1] - h[i];
  h.back() = t - h.back();
  inplace_merge(h.begin(), h.begin() + l, h.end());
  int j = 0;
  for (int i = 1; i < (int)(h.size()); ++i)
    if (h[j] | h[i])
      swap(h[++j], h[i]);
    else
      h[j] = h[j] + h[i];
  h.resize(j + 1);
}
bool in(P const &o) {
  int l = 0, r = h.size() - 1;
  while (r > l) {
    int m = l + r + 1 >> 1;
    if ((o - h[0] | h[m] - h[0]) >= 0)
      r = m - 1;
    else
      l = m;
  }
  if (l + 1 == h.size()) return false;
  if (l == 0 && (h[1] - h[0] | o - h[0]) == 0)
    return (h[2] - h[1] | o - h[1]) >= 0;
  return (h[l + 1] - h[l] | o - h[l]) >= 0;
}
int main() {
  for (int i = 0; i < (int)(3); ++i) sc();
  P t = h[0];
  h[0] = b;
  for (int i = 1; i < (int)(h.size()); ++i) {
    P tt = h[i];
    h[i] = t + h[i - 1];
    t = tt;
  }
  int m;
  scanf("%d", &m);
  while (m--) {
    P p;
    p.sc();
    printf("%s\n", in(p * 3) ? "YES" : "NO");
  }
}