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 = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;
int MAXS = 997;
const int MAXSS = 1100007;
const long double PI = acos(-1.0);
const long double EPS = 0.015;
const long double RATIO = 0.9;
struct cT {
  cT() : x(0), y(0) {}
  cT(long double _x, long double _y) : x(_x), y(_y) {}
  cT operator+(const cT &a) const { return cT(x + a.x, y + a.y); }
  void operator+=(const cT &a) { (*this) = (*this) + a; }
  cT operator-(const cT &a) const { return cT(x - a.x, y - a.y); }
  void operator-=(const cT &a) { (*this) = (*this) - a; }
  long double ang() { return atan2(y, x); }
  long double abs() { return x * x + y * y; }
  long double len() { return sqrt(abs()); }
  cT rot(long double ang) {
    long double ca = cos(ang), sa = sin(ang);
    return cT(x * ca - y * sa, x * sa + y * ca);
  }
  bool operator<(const cT &a) const { return x < a.x; }
  long double x, y;
} c1[MAXN], c2[MAXN];
int n, n1, n2;
pair<cT, int> s1[MAXN];
pair<long double, pair<int, int> > s2[MAXSS];
int ans2[MAXN];
bool vis1[MAXN];
void init();
void input();
void work();
void check(int a11, int a12, int a21, int a22);
int main() {
  init();
  input();
  work();
}
void init() {
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
}
void input() {
  scanf("%d", &n);
  scanf("%d", &n1);
  double tx, ty;
  for (int i = 1; i <= n1; ++i)
    scanf("%lf%lf", &tx, &ty), c1[i].x = tx, c1[i].y = ty;
  scanf("%d", &n2);
  for (int i = 1; i <= n2; ++i)
    scanf("%lf%lf", &tx, &ty), c2[i].x = tx, c2[i].y = ty;
}
void work() {
  MAXS = (((MAXS) < (n)) ? (MAXS) : (n));
  for (int i = 1; i <= n1; ++i) s1[i] = make_pair(c1[i], i);
  sort(s1 + 1, s1 + 1 + n1);
  int k2 = 0;
  for (int i = 1; i <= MAXS; ++i) {
    for (int j = i + 1; j <= MAXS; ++j) {
      s2[++k2] = make_pair((c2[j] - c2[i]).len(), make_pair(i, j));
    }
  }
  sort(s2 + 1, s2 + 1 + k2);
  long double nd;
  int np;
  while (1) {
    int i = rand() % MAXS + 1, j = rand() % MAXS + 1;
    if (i ^ j) {
      nd = (c1[j] - c1[i]).len();
      np =
          lower_bound(s2 + 1, s2 + 1 + k2, make_pair(nd, make_pair(0, 0))) - s2;
      for (int k = np; k <= k2; ++k) {
        if (s2[k].first - nd < EPS)
          check(i, j, s2[k].second.first, s2[k].second.second);
        else
          break;
      }
      for (int k = np - 1; k > 0; --k) {
        if (nd - s2[k].first < EPS)
          check(i, j, s2[k].second.first, s2[k].second.second);
        else
          break;
      }
    }
  }
}
void check(int a11, int a12, int a21, int a22) {
  long double ang1 = (c1[a12] - c1[a11]).ang(),
              ang2 = (c2[a22] - c2[a21]).ang();
  long double ang = ang1 - ang2;
  cT ra21 = c2[a21].rot(ang);
  cT d = c1[a11] - ra21;
  int np, cc = 0;
  cT nr;
  for (int i = 1; i <= n2; ++i) {
    nr = c2[i].rot(ang) + d;
    np = lower_bound(s1 + 1, s1 + 1 + n1, make_pair(nr, 0)) - s1;
    for (int k = np; k <= n1; ++k) {
      if (s1[k].first.x - nr.x < EPS) {
        if ((((s1[k].first.y - nr.y) >= 0) ? (s1[k].first.y - nr.y)
                                           : (-(s1[k].first.y - nr.y))) < EPS &&
            !vis1[s1[k].second]) {
          ans2[i] = s1[k].second;
          vis1[s1[k].second] = true;
          break;
        }
      } else
        break;
    }
    if (!ans2[i]) {
      for (int k = np - 1; k > 0; --k) {
        if (nr.x - s1[k].first.x < EPS) {
          if ((((s1[k].first.y - nr.y) >= 0)
                   ? (s1[k].first.y - nr.y)
                   : (-(s1[k].first.y - nr.y))) < EPS &&
              !vis1[s1[k].second]) {
            ans2[i] = s1[k].second;
            vis1[s1[k].second] = true;
            break;
          }
        } else
          break;
      }
    }
    if (ans2[i]) ++cc;
    if (i >= 100 && cc * 5 < i) {
      for (int j = 1; j <= i; ++j) {
        vis1[ans2[j]] = false;
        ans2[j] = 0;
      }
      return;
    }
  }
  if (cc > RATIO * n) {
    int nc = 0;
    for (int i = 1; i <= n2; ++i) {
      if (ans2[i]) {
        printf("%d %d\n", ans2[i], i);
        if (++nc == n) break;
      }
    }
    if (nc < n) {
      int i1 = 1;
      for (int i = 1; i <= n2; ++i) {
        if (!ans2[i]) {
          while (vis1[i1]) ++i1;
          printf("%d %d\n", i1, i);
          vis1[i1] = true;
          if (++nc == n) break;
        }
      }
    }
    exit(0);
  }
  memset(ans2, 0, sizeof(ans2));
  memset(vis1, 0, sizeof(vis1));
}