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;
int n, n1, n2;
pair<double, double> p1[1234567], p2[1234567];
pair<double, pair<int, int> > ps[5050666];
int pn = 0;
inline double dis(pair<double, double> x) {
  return x.first * x.first + x.second * x.second;
}
inline double ang(pair<double, double> x) { return atan2l(x.second, x.first); }
inline pair<double, double> operator-(pair<double, double> a,
                                      pair<double, double> b) {
  return pair<double, double>(a.first - b.first, a.second - b.second);
}
inline pair<double, double> operator+(pair<double, double> a,
                                      pair<double, double> b) {
  return pair<double, double>(a.first + b.first, a.second + b.second);
}
inline double dis(pair<double, double> x, pair<double, double> y) {
  return dis(x - y);
}
double co, si;
inline pair<double, double> rot(pair<double, double> g) {
  return pair<double, double>(g.first * co - g.second * si,
                              g.first * si + g.second * co);
}
pair<pair<double, double>, int> q1[1234567], qt[1234567];
bool vis[1234567];
void chk(pair<double, double> a1, pair<double, double> a2,
         pair<double, double> b1, pair<double, double> b2) {
  cerr << "=";
  double x1 = ang(a2 - a1), x2 = ang(b2 - b1);
  co = cosl(x2 - x1);
  si = sinl(x2 - x1);
  int tt = 0;
  for (int i = 1; i <= n1 && i <= 3000; ++i)
    qt[++tt].first = rot(p1[i] - a1) + b1;
  sort(qt + 1, qt + tt + 1);
  int sb = 0;
  for (int i = 1; i <= n2 && i <= 3000; ++i) {
    int o = lower_bound(qt + 1, qt + tt + 1, make_pair(p2[i], 0)) - qt;
    bool s = 0;
    for (int j = max(o - 10, 1); j <= min(o + 10, n1); ++j)
      if (dis(qt[j].first, p2[i]) < 1) {
        s = 1;
        break;
      }
    sb += s;
  }
  if (sb < 5) return;
  for (int i = 1; i <= n1; ++i)
    q1[i].first = rot(p1[i] - a1) + b1, q1[i].second = i, vis[i] = 0;
  sort(q1 + 1, q1 + n1 + 1);
  vector<pair<int, int> > rs;
  int fail = 0;
  for (int i = 1; i <= n2; ++i) {
    int o = lower_bound(q1 + 1, q1 + n1 + 1, make_pair(p2[i], 0)) - q1;
    bool s = 0;
    for (int j = max(o - 10, 1); j <= min(o + 10, n1); ++j) {
      if (dis(q1[j].first, p2[i]) < 1 && !vis[q1[j].second]) {
        rs.push_back(pair<int, int>(q1[j].second, i));
        fail = 0;
        s = 1;
        vis[q1[j].second] = 1;
        break;
      }
    }
    if (!s) ++fail;
    if (fail > 100) return;
  }
  random_shuffle(rs.begin(), rs.end());
  if (rs.size() >= n * 0.95) {
    if (rs.size() > n) rs.resize(n);
    for (int _ = 0; _ < rs.size(); ++_)
      printf("%d %d\n", rs[_].first, rs[_].second);
    for (int _ = rs.size(); _ < n; ++_) printf("1 1\n");
    exit(0);
  }
}
pair<double, double> md;
double gg[1234567];
bool cmp(int a, int b) { return gg[a] < gg[b]; }
inline bool myc(const pair<double, pair<int, int> >& a,
                const pair<double, pair<int, int> >& b) {
  return a.first < b.first;
}
int main() {
  cin >> n >> n1;
  for (int i = 1; i <= n1; ++i) cin >> p1[i].first >> p1[i].second;
  cin >> n2;
  for (int i = 1; i <= n2; ++i) cin >> p2[i].first >> p2[i].second;
  for (int i = 1; i <= n1 && pn < 4000000; ++i) {
    md = p1[i];
    vector<int> rs;
    for (int j = 1; j <= n1; ++j)
      if (j != i) rs.push_back(j), gg[j] = ang(p1[j] - md);
    sort(rs.begin(), rs.end(), cmp);
    for (unsigned _ = 0; _ < rs.size(); ++_) {
      int x = rs[_], y = rs[(_ + 1) % rs.size()];
      ps[++pn] = make_pair(dis(p1[x], p1[y]), pair<int, int>(x, y));
    }
  }
  while (pn < 5000000) {
    int x = rand() % n1 + 1, y = rand() % n1 + 1;
    if (x != y) ps[++pn] = make_pair(dis(p1[x], p1[y]), pair<int, int>(x, y));
  }
  sort(ps + 1, ps + 1 + pn, myc);
  for (int w = 1; w <= n2; ++w) {
    cerr << "=====\n";
    md = p2[w];
    vector<int> rs;
    for (int j = 1; j <= n2; ++j)
      if (j != w) rs.push_back(j), gg[j] = ang(p2[j] - md);
    sort(rs.begin(), rs.end(), cmp);
    int uu = 0;
    int p = rand() % rs.size();
    for (unsigned _ = 0; _ < rs.size(); ++_) {
      int i = rs[(_ + p) % rs.size()], j = rs[(_ + 1 + p) % rs.size()];
      double dx = dis(p2[i], p2[j]);
      int s = lower_bound(ps + 1, ps + 1 + pn,
                          make_pair(dx, pair<int, int>(0, 0))) -
              ps;
      for (int k = max(s - 5, 1); k <= min(s + 5, pn); ++k)
        if (fabs(dx - ps[k].first) < 0.1) {
          chk(p1[ps[k].second.first], p1[ps[k].second.second], p2[i], p2[j]);
          chk(p1[ps[k].second.first], p1[ps[k].second.second], p2[j], p2[i]);
          ++uu;
        }
      if (uu > 30) break;
    }
    int i = rand() % n2 + 1, j = rand() % n2 + 1;
    if (i == j) continue;
    double dx = dis(p2[i], p2[j]);
    int s =
        lower_bound(ps + 1, ps + 1 + pn, make_pair(dx, pair<int, int>(0, 0))) -
        ps;
    for (int k = max(s - 10, 1); k <= min(s + 10, pn); ++k)
      if (fabs(dx - ps[k].first) < 0.01) {
        chk(p1[ps[k].second.first], p1[ps[k].second.second], p2[i], p2[j]);
        chk(p1[ps[k].second.first], p1[ps[k].second.second], p2[j], p2[i]);
      }
  }
  throw "GG";
}