Problem: The stardate is 2015, and Death Stars are bigger than ever! This time, two rebel spies have yet again given Heidi two maps with the possible locations of the Death Stars.

Heidi has now received two maps with possible locations of N Death Stars. She knows that each of the maps is possibly corrupted, and may contain some stars that are not Death Stars. Furthermore, each of the maps was created from a different point of view. Hence, stars that are shown in one of the maps are rotated and translated with respect to the other map. Now Heidi wants to find out which of the stars shown in both maps are actually Death Stars, and the correspondence between the Death Stars on the two maps. 

Input

The first line of the input contains an integer N (1000 ≤ N ≤ 50000) – the number of Death Stars. The second line of the input contains an integer N1 (N ≤ N1 ≤ 1.5·N) – the number of stars in the first map. The next N1 lines specify the coordinates of the stars in the first map. The i-th line contains two space-separated floating-point numbers xi and yi with two decimal digits of precision each, representing the coordinates of the i-th star in the first map.

The next line of the input contains an integer N2 (N ≤ N2 ≤ 1.5·N) – the number of stars in the second map. The next N2 lines contain locations of the stars in the second map, given in the same format as for the first map. 

Output

You should output exactly N lines, each containing a space-separated pair of integers i1 and i2. Each such line should indicate that the star numbered i1 in the first map corresponds to the star numbered i2 in the second map. Your answer will be considered correct if over 90% of the distinct pairs listed in your output are indeed correct.

Note

The tests are generated in the following way: 

  * The number of Death Stars N is pre-selected in some way. 
  * The numbers of stars on the first and on the second map, N1 and N2, are selected uniformly at random between 1.0 × N and 1.5 × N. 
  * N Death Stars are generated at random, with coordinates between  - 10000 and 10000. 
  * Additional N1 - N and N2 - N stars for the first and for the second map respectively are generated in the same way. 
  * A translation vector (dx, dy) is generated, with dx and dy selected uniformly at random between  - 10000 and 10000. Each point in the first map is translated by (dx, dy). 
  * A rotation angle θ is generated, with θ selected uniformly at random between 0 and 2π. Each point in the first map is rotated by an angle of θ around the origin. 
  * Translations and rotations for the second map are generated and applied in the same way. 
  * The order of points is randomly permuted for both maps. 
  * The test case is saved, with each point written with two decimal digits of precision. 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f;
const long long MOD = 1000000007;
const int IT_MAX = 1 << 17;
const double EPS = 1e-9;
const double PI = acos(-1);
const int MX = 100005;
pair<double, double> operator+(pair<double, double> l, pair<double, double> r) {
  return pair<double, double>(l.first + r.first, l.second + r.second);
}
pair<double, double> operator-(pair<double, double> l, pair<double, double> r) {
  return pair<double, double>(l.first - r.first, l.second - r.second);
}
double operator*(pair<double, double> a, pair<double, double> b) {
  return a.first * b.first + a.second * b.second;
}
pair<double, double> operator*(pair<double, double> l, double r) {
  return pair<double, double>(l.first * r, l.second * r);
}
double operator/(pair<double, double> l, pair<double, double> r) {
  return l.first * r.second - l.second * r.first;
}
pair<double, double> r90(pair<double, double> c) {
  return pair<double, double>(-c.second, c.first);
}
double size(pair<double, double> c) { return hypot(c.first, c.second); }
double sq(double x) { return x * x; }
double size2(pair<double, double> c) { return sq(c.first) + sq(c.second); }
pair<double, double> unit(double a) {
  return pair<double, double>(cos(a), sin(a));
}
pair<double, double> rotate(pair<double, double> v, double a) {
  return unit(a) * v.first + unit(a + PI / 2) * v.second;
}
int intersect(pair<double, double> a, pair<double, double> b,
              pair<double, double> u, pair<double, double> v,
              pair<double, double> &des) {
  if (abs(u / v) < EPS) return 0;
  des = pair<double, double>(((a - u) / v) / (v / b), ((a - u) / b) / (v / b));
  return 1;
}
struct circle {
  circle(pair<double, double> O, double r) : O(O), r(r) {}
  circle() {}
  pair<double, double> O;
  double r;
};
int get_circle(pair<double, double> p0, pair<double, double> p1,
               pair<double, double> p2, circle &des) {
  pair<double, double> a = (p0 + p1) * 0.5, b = r90(p0 - p1);
  pair<double, double> u = (p0 + p2) * 0.5, v = r90(p0 - p2), R;
  if (!intersect(a, b, u, v, R)) return 0;
  des = circle(a + b * R.first, size(a + b * R.first - p0));
  return 1;
}
struct node {
  node(int a, int b, int c, circle X) : a(a), b(b), c(c), X(X) {}
  int a, b, c;
  circle X;
};
node make_circle(vector<int> Q, pair<double, double> D[MX]) {
  if (Q.size() == 0)
    return node(-1, -1, -1, circle(pair<double, double>(0, 0), 0));
  if (Q.size() == 1) return node(Q[0], -1, -1, circle(D[Q[0]], 0));
  circle res;
  for (int i = 0; i < Q.size(); i++) {
    swap(Q.back(), Q[i]);
    res = circle((D[Q[0]] + D[Q[1]]) * 0.5, size(D[Q[0]] - D[Q[1]]) / 2);
    bool ch = 1;
    for (int c : Q) {
      if (size2(D[c] - res.O) > sq(res.r) + 1e-6) ch = 0;
    }
    if (ch) return node(Q[0], Q[1], -1, res);
    swap(Q.back(), Q[i]);
  }
  get_circle(D[Q[0]], D[Q[1]], D[Q[2]], res);
  return node(Q[0], Q[1], Q[2], res);
}
node smallest_circle(vector<int> &P, vector<int> &Q, int N,
                     pair<double, double> D[MX]) {
  node c = make_circle(Q, D);
  if (N == 0 || Q.size() >= 3) return c;
  for (int i = 0; i < N; i++) {
    if (size2(c.X.O - D[P[i]]) > sq(c.X.r)) {
      Q.push_back(P[i]);
      c = smallest_circle(P, Q, i, D);
      Q.pop_back();
    }
  }
  return c;
}
int counter = 0;
void get_enc(vector<int> L, vector<int> X, vector<node> &ans,
             pair<double, double> D[MX], double prob = 1) {
  if (prob < 1e-4) return;
  counter++;
  vector<int> P, Q;
  random_shuffle(L.begin(), L.end());
  for (int c : X) P.push_back(c);
  for (int c : L) P.push_back(c);
  node x = smallest_circle(P, Q, L.size(), D);
  ans.push_back(x);
  vector<int> t1;
  auto is_in = [](vector<int> &X, int x) {
    for (int c : X)
      if (c == x) return true;
    return false;
  };
  if (!is_in(X, x.a)) t1.push_back(x.a);
  if (!is_in(X, x.b)) t1.push_back(x.b);
  if (!is_in(X, x.c)) t1.push_back(x.c);
  for (int c : t1) {
    for (int j = 0; j < L.size(); j++)
      if (L[j] == c) L.erase(L.begin() + j);
    get_enc(L, X, ans, D, prob / 3);
    prob = prob * 2 / 3;
    X.push_back(c);
  }
}
pair<double, double> D1[MX], D2[MX];
int N, N1, N2;
map<pair<int, int>, int> Mx;
void check(pair<double, double> O1, pair<double, double> O2, double a) {
  auto move = [&](pair<double, double> c) { return rotate(c - O1, a) + O2; };
  counter++;
  int corr = 0;
  vector<pair<int, int> > ansv;
  for (int i = 1; i <= N1; i++) {
    pair<double, double> ex = move(D1[i]);
    int tx = (int)(ex.first * 100 + 0.5);
    int ty = (int)(ex.second * 100 + 0.5);
    int f = 0;
    for (int dx = -1; dx <= 1; dx++)
      for (int dy = -1; dy <= 1; dy++)
        if (f == 0) {
          if (Mx.find(pair<int, int>(tx + dx, ty + dy)) != Mx.end()) {
            int idx = Mx[pair<int, int>(tx + dx, ty + dy)];
            ansv.emplace_back(i, idx);
            f = 1;
          }
        }
    corr += f;
    if (i > 100 && ((double)corr / i) * N1 < N * 0.5) break;
  }
  if ((int)(ansv).size() > 0.91 * N) {
    int chkA[MX] = {}, chkB[MX] = {};
    for (pair<int, int> e : ansv) chkA[e.first] = chkB[e.second] = 1;
    int ia = 1, ib = 1;
    while ((int)(ansv).size() < N) {
      while (chkA[ia] == 1) ++ia;
      while (chkB[ib] == 1) ++ib;
      ansv.push_back(pair<int, int>(ia, ib));
      ++ia;
      ++ib;
    }
    for (pair<int, int> e : ansv) printf("%d %d\n", e.first, e.second);
    exit(0);
  }
}
int main() {
  scanf("%d", &N);
  scanf("%d", &N1);
  for (int i = 1; i <= N1; i++) scanf("%lf%lf", &D1[i].first, &D1[i].second);
  scanf("%d", &N2);
  for (int i = 1; i <= N2; i++) scanf("%lf%lf", &D2[i].first, &D2[i].second);
  for (int i = 1; i <= N2; i++) {
    int tx = (int)(D2[i].first * 100 + 0.5);
    int ty = (int)(D2[i].second * 100 + 0.5);
    Mx[pair<int, int>(tx, ty)] = i;
  }
  vector<int> t1, t2;
  vector<node> A1, A2;
  for (int i = 1; i <= N1; i++) t1.push_back(i);
  get_enc(t1, t2, A1, D1);
  t1.clear();
  for (int i = 1; i <= N2; i++) t1.push_back(i);
  get_enc(t1, t2, A2, D2);
  for (node a1 : A1) {
    for (node a2 : A2) {
      if (fabs(a1.X.r - a2.X.r) > 0.1) continue;
      pair<double, double> P1[] = {D1[a1.a], D1[a1.b], D1[a1.c]};
      pair<double, double> P2[] = {D2[a2.a], D2[a2.b], D2[a2.c]};
      for (pair<double, double> &c : P1) c = c - a1.X.O;
      for (pair<double, double> &c : P2) c = c - a2.X.O;
      int O[3] = {0, 1, 2};
      do {
        int ch = 1;
        double t = atan2(P1[0] / P2[O[0]], P1[0] * P2[O[0]]);
        for (int i = 1; i < 3; i++) {
          double u = atan2(P1[i] / P2[O[i]], P1[i] * P2[O[i]]);
          if (fabs(t - u) < EPS) ch = 0;
        }
        check(a1.X.O, a2.X.O, t);
      } while (next_permutation(O, O + 3));
    }
  }
}