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 long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
double pi = acos(-1.);
struct cd {
  double a, b;
  cd() {}
  cd(double a, double b) : a(a), b(b) {}
  cd operator+(const cd &y) const { return (cd){a + y.a, b + y.b}; }
  cd operator-(const cd &y) const { return (cd){a - y.a, b - y.b}; }
  cd operator*(const cd &y) const {
    return (cd){a * y.a - b * y.b, a * y.b + b * y.a};
  }
  cd operator!() const { return (cd){a, -b}; };
  double len() { return a * a + b * b; }
};
bool operator<(cd a, cd b) { return a.a < b.a; }
const int N = 101000;
int n, n1, n2;
cd p[N], q1[N], r1[N], q2[N], r2[N];
cd gen() {
  return cd(rand() % 200000001 * 1e-4 - 10000,
            rand() % 200000001 * 1e-4 - 10000);
}
cd ang(double x) { return cd(cos(x), sin(x)); }
cd rrrrrd(cd p) {
  double x = p.a, y = p.b;
  x = floor(x * 100 + 0.5) * 0.01, y = floor(y * 100 + 0.5) * 0.01;
  return cd(x, y);
}
double eval(cd p, cd *q, int n) {
  double mxx = -1e6, mnx = 1e6, mxy = -1e6, mny = 1e6;
  for (int i = 0; i < n; i++) {
    cd z = q[i] * p;
    mxx = max(mxx, z.a);
    mxy = max(mxy, z.b);
    mnx = min(mnx, z.a);
    mny = min(mny, z.b);
  }
  return mxx + mxy - mnx - mny;
}
void recov(cd *q, cd *r, cd p, int n) {
  double mxx = -1e6, mnx = 1e6, mxy = -1e6, mny = 1e6;
  for (int i = 0; i < n; i++) {
    cd z = q[i] * p;
    mxx = max(mxx, z.a);
    mxy = max(mxy, z.b);
    mnx = min(mnx, z.a);
    mny = min(mny, z.b);
    r[i] = z;
  }
  cd d(-0.5 * (mxx + mnx), -0.5 * (mxy + mny));
  for (int i = 0; i < n; i++) r[i] = r[i] + d;
}
void gao(cd *q, cd *r, int n) {
  double vl = 0, vr = pi / 2;
  for (int i = 0; i < 50; i++) {
    double fl = (vl + vl + vr) / 3, fr = (vl + vr + vr) / 3;
    if (eval(ang(-fl), q, n) > eval(ang(-fr), q, n))
      vl = fl;
    else
      vr = fr;
  }
  recov(q, r, ang(-vl), n);
}
void gen(int n, cd *p, int &n2, cd *q) {
  n2 = n + rand() % (n / 2 + 1);
  for (int i = 0; i < n; i++) q[i] = p[i];
  for (int i = n; i < n2; i++) q[i] = gen();
  double t = rand() % 100000000 * 2e-8 * pi;
  cd c = ang(t);
  cd d = gen();
  for (int i = 0; i < n2; i++) q[i] = rrrrrd(q[i] * c + d);
}
int rk[N], vis1[N], vis2[N], perm[N], mat[N];
cd pnt[N];
pair<int, int> pr[4][N];
double ret[4], dd[N];
void match(cd *r1, cd *r2, int n1, int n2, int n, pair<int, int> *pr,
           double &ret) {
  for (int i = 0; i < n1; i++) rk[i] = i, vis1[i] = 0;
  sort(rk, rk + n1, [&](int a, int b) { return r1[a] < r1[b]; });
  for (int i = 0; i < n1; i++) pnt[i] = r1[rk[i]];
  for (int i = 0; i < n2; i++) {
    int z = lower_bound(pnt, pnt + n1, r2[i]) - pnt;
    double dis = 1e10;
    int pv = -1;
    for (int j = 0; j < 100; j++) {
      bool fd = 0;
      if (z + j < n1 && pnt[z + j].a <= r2[i].a + dis) {
        fd = 1;
        double w = (pnt[z + j] - r2[i]).len();
        if (w < dis) dis = w, pv = z + j;
      }
      if (z - j >= 0 && pnt[z - j].a >= r2[i].a - dis) {
        fd = 1;
        double w = (pnt[z - j] - r2[i]).len();
        if (w < dis) dis = w, pv = z - j;
      }
      if (!fd) break;
    }
    mat[i] = pv;
    dd[i] = dis;
  }
  for (int i = 0; i < n2; i++) perm[i] = i, vis2[i] = 0;
  sort(perm, perm + n2, [&](int a, int b) { return dd[a] < dd[b]; });
  int cur = 0;
  ret = 0;
  for (int i = 0; i < n2; i++) {
    int u = perm[i], v = rk[mat[u]];
    if (vis1[v]) continue;
    pr[cur] = make_pair(v, u);
    ret += dd[u];
    vis2[u] = 1;
    vis1[v] = 1;
    cur++;
    if (cur >= n) break;
  }
  if (cur < n) {
    set<int> cand;
    for (int i = 0; i < n1; i++)
      if (!vis1[i]) cand.insert(i);
    for (int i = 0; i < n2; i++)
      if (!vis2[i]) {
        pr[cur++] = make_pair(*cand.begin(), i);
        cand.erase(cand.begin());
        if (cur >= n) break;
      }
  }
}
int main() {
  scanf("%d", &n);
  scanf("%d", &n1);
  for (int i = 0; i < n1; i++) scanf("%lf%lf", &q1[i].a, &q1[i].b);
  scanf("%d", &n2);
  for (int i = 0; i < n2; i++) scanf("%lf%lf", &q2[i].a, &q2[i].b);
  gao(q1, r1, n1);
  gao(q2, r2, n2);
  for (int it = 0; it < 4; it++) {
    match(r1, r2, n1, n2, n, pr[it], ret[it]);
    cd rot(0, 1);
    for (int i = 0; i < n2; i++) r2[i] = r2[i] * rot;
  }
  int z = min_element(ret, ret + 4) - ret;
  for (int i = 0; i < n; i++)
    printf("%d %d\n", pr[z][i].first + 1, pr[z][i].second + 1);
}