#include <bits/stdc++.h>
using namespace std;

const int N = 2.1e5;

struct P {
  int xl, xr, yl, yr, z, id;
  bool operator<(const P& o) const {
    return z < o.z;
  }
} a[N];

struct S {
  int x, y;
} s[N];

vector<int> ex = {0}, ey = {0};
int n, m, ans[N];

int dist(const vector<int>& e, int x) {
  return upper_bound(e.begin(), e.end(), x) - e.begin() - 1;
}

struct KDN {
  set<int> a;
  int w, xl, xr, yl, yr;
  bool sx;
  bool leaf = true;
  KDN *lt = nullptr, *ge = nullptr;
} root;

void ds_split(KDN& d) {
  d.xr = d.yr = 0;
  d.xl = d.yl = N;
  for (int i : d.a) {
    d.xl = min(d.xl, s[i].x);
    d.yl = min(d.yl, s[i].y);
    d.xr = max(d.xr, s[i].x);
    d.yr = max(d.yr, s[i].y);
    //cerr << i << ",";
  }
  //cerr << endl;

  int sz = d.a.size();
  if ((d.xr == d.xl && d.yr == d.yl) || sz < 9) {
    d.leaf = true;
    return;
  }

  d.lt = new KDN;
  d.ge = new KDN;

  vector<pair<int, int>> p;
  d.sx = d.xr - d.xl > d.yr - d.yl;
  if (d.sx) {
    for (int i : d.a)
      p.emplace_back(s[i].x, i);
    auto sp = p.begin() + (sz+1)/2;
    nth_element(p.begin(), sp, p.end());
    d.w = sp->first;
    if (d.xl == d.w) ++d.w;
    for (int i : d.a)
      if (s[i].x < d.w) {
        d.lt->a.insert(i);
      } else {
        d.ge->a.insert(i);
      }
  } else {
    for (int i : d.a)
      p.emplace_back(s[i].y, i);
    auto sp = p.begin() + (sz+1)/2;
    nth_element(p.begin(), sp, p.end());
    d.w = sp->first;
    if (d.yl == d.w) ++d.w;
    for (int i : d.a)
      if (s[i].y < d.w) {
        d.lt->a.insert(i);
      } else {
        d.ge->a.insert(i);
      }
  }

  if (d.lt->a.empty()) {
    delete d.lt;
    d.lt = nullptr;
  } else ds_split(*d.lt);

  if (d.ge->a.empty()) {
    delete d.ge;
    d.ge = nullptr;
  } else ds_split(*d.ge);
}

void ds_build() {
  for (int i = 0; i < m; ++i) {
    root.a.insert(i);
  }
  ds_split(root);
}

int ds_fn(const KDN& d, const P& p) {
  if (d.a.empty()) return m;

  if (p.xl > d.xr || p.xr < d.xl || p.yl > d.yr || p.yr < d.yl) return m;

  if (p.xl <= d.xl && d.xr <= p.xr && p.yl <= d.yl && d.yr <= p.yr) {
    return *d.a.begin();
  }

  if (d.leaf) {
    for (int i : d.a) {
      if (p.xl <= s[i].x && s[i].x <= p.xr &&
        p.yl <= s[i].y && s[i].y <= p.yr) {
          return i;
        }
    }
    return m;
  }

  int ans = m;
  if (d.lt) ans = min(ans, ds_fn(*d.lt, p));
  if (d.ge) ans = min(ans, ds_fn(*d.ge, p));
  return ans;
}

int ds_findmin(const P& p) {
  return ds_fn(root, p);
}

void ds_remove(int i) {
  KDN* p = &root;
  while (p) {
    p->a.erase(i);
    if (p->leaf) break;
    bool use_lt = true;
    if (p->sx && s[i].x >= p->w) use_lt = false;
    if (!p->sx && s[i].y >= p->w) use_lt = false;
    p = use_lt ? p->lt : p->ge;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int xl, xr, yl, yr, z;
    scanf("%d%d%d%d%d", &xl, &xr, &yl, &yr, &z);
    a[i].xl = xl;
    a[i].xr = xr;
    a[i].yl = yl;
    a[i].yr = yr;
    a[i].z = z;
    a[i].id = i + 1;
    ex.push_back(xl);
    ex.push_back(xr + 1);
    ey.push_back(yl);
    ey.push_back(yr + 1);
  }
  sort(ex.begin(), ex.end());
  ex.resize(unique(ex.begin(), ex.end()) - ex.begin());
  sort(ey.begin(), ey.end());
  ey.resize(unique(ey.begin(), ey.end()) - ey.begin());
  for (int i = 0; i < n; ++i) {
    a[i].xl = dist(ex, a[i].xl);
    a[i].xr = dist(ex, a[i].xr);
    a[i].yl = dist(ey, a[i].yl);
    a[i].yr = dist(ey, a[i].yr);
  }
  scanf("%d", &m);
  for (int i = 0, x, y; i < m; ++i) {
    scanf("%d%d", &x, &y);
    s[i].x = dist(ex, x);
    s[i].y = dist(ey, y);
  }
  ds_build();
  sort(a, a + n);
  for (const P& p : a) {
    int x = ds_findmin(p);
    if (x < m) {
      ans[x] = p.id;
      ds_remove(x);
    }
  }

  for (int i = 0; i < m; ++i) printf("%d\n", ans[i]);
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1.1e5;
int n, m;
struct P {
    int xl, xr, yl, yr, z, id;
    bool operator<(const P& o) const {
        return z < o.z;
    }
} a[N];
struct S { int x, y; } b[N];

struct Node {
    int l, r, h, v;
    int yl, yr, mi;
} T[N * 18];
int top, f[N], g[N];

vector<int> ex;
int ans[N], nx;

void mt(int rt) {
  if (rt) {
    T[rt].yl = min(T[T[rt].l].yl, b[T[rt].v].y);
    T[rt].yr = max(T[T[rt].r].yr, b[T[rt].v].y);
    T[rt].mi = min(T[rt].v, min(T[T[rt].l].mi, T[T[rt].r].mi));
  }
}
void dbg(int rt, int lv = 0) {
  if (!lv) cerr << "----\n";
  if (!rt) return;
  dbg(T[rt].l, lv + 1);
  for (int i = 0; i < lv; ++i) cerr << "  ";
  cerr << T[rt].v << endl;
  dbg(T[rt].r, lv + 1);
}
int splt(int rt, int*l, int*r, int i) {
  if (!rt) return *l = *r = 0;
  if (b[T[rt].v].y < b[i].y || (b[T[rt].v].y == b[i].y && T[rt].v < i)) {
    int res = splt(T[rt].r, l, r, i);
    T[rt].r = *l;
    mt(*l = rt);
    return res;
  }
  int res = splt(T[rt].l, l, r, i);
  if (res) {
    T[rt].l = *r;
    mt(*r = rt);
    return res;
  }
  *r = T[rt].r;
  T[rt].l = T[rt].r = 0;
  mt(rt);
  return rt;
}
int mrg(int l, int r) {
  if (!l || !r) return l + r;
  if (T[l].h > T[r].h) {
    T[l].r = mrg(T[l].r, r);
    mt(l);
    return l;
  }
  T[r].l = mrg(l, T[r].l);
  mt(r);
  return r;
}

void ins2(int *rt, int i) {
  int l, r;
  *rt = splt(*rt, &l, &r, i);
  T[++top].v = i;
  T[top].h = rand();
  mt(top);
  *rt = mrg(l, mrg(top, mrg(*rt, r)));
}
void del2(int *rt, int i) {
  int l, r;
  *rt = splt(*rt, &l, &r, i);
  *rt = mrg(l, r);
}
int fnd2(int rt, int l, int r) {
  if (T[rt].yl > r || T[rt].yr < l) return m;
  if (l <= T[rt].yl && T[rt].yr <= r) return T[rt].mi;
  return min(fnd2(T[rt].l, l, r), fnd2(T[rt].r, l, r));
}

void ins(int i) {
  int x = b[i].x + 1;
  if (x % 2 == 0) ins2(&g[x], i);
  while (x <= nx) {
    ins2(&f[x], i);
    x += x&-x;
  }
}
void del(int i) {
  int x = b[i].x + 1;
  if (x % 2 == 0) del2(&g[x], i);
  while (x <= nx) {
    del2(&f[x], i);
    x += x&-x;
  }
}
int fnd(const P& p) {
  int x = p.xr;
  int ans = m;
  //cerr << "fnd\n";
  while (x > p.xl) {
    if ((x&x-1) >= p.xl) {
      //dbg(f[x]);
      ans = min(ans, fnd2(f[x], p.yl, p.yr));
      x &= x - 1;
    } else {
      //dbg(g[x]);
      ans = min(ans, fnd2(g[x], p.yl, p.yr));
      --x;
    }
  }
  return ans;
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d%d%d%d", &a[i].xl, &a[i].xr, &a[i].yl, &a[i].yr, &a[i].z);
        a[i].id = i + 1;
    }
    sort(a, a + n);
    scanf("%d", &m);
    for (int i = 0; i < m; ++i) {
        scanf("%d%d", &b[i].x, &b[i].y);
        ex.push_back(b[i].x);
    }
    sort(ex.begin(), ex.end());
    ex.resize(unique(ex.begin(), ex.end()) - ex.begin());
    nx = ex.size();

    srand(950516);
    T[0].mi = m;
    T[0].yl = 1e8;
    T[0].yr = -1e8;
    for (int i = 0; i < m; ++i) {
        b[i].x = lower_bound(ex.begin(), ex.end(), b[i].x) - ex.begin();
        ins(i);
    }

    //for (int i = 1; i <= nx; ++i) {
      //cerr << ">> " << i << endl;
      //dbg(i%2?f[i]:g[i]);
      //dbg(f[i]);
    //}

    for (int i = 0; i < n; ++i) {
        auto& p = a[i];
        p.xl = lower_bound(ex.begin(), ex.end(), p.xl) - ex.begin();
        p.xr = upper_bound(ex.begin(), ex.end(), p.xr) - ex.begin();
        int x = fnd(p);
        if (x < m) {
            ans[x] = p.id;
            del(x);
        }
    }
    for (int i = 0; i < m; ++i) printf("%d\n", ans[i]);
}


#include <bits/stdc++.h>
using namespace std;

const int N = 2.1e5;

struct P {
  int xl, xr, yl, yr, z, id;
  bool operator<(const P& o) const {
    return z < o.z;
  }
} a[N];

struct S {
  int x, y;
} s[N];

vector<int> ex = {0}, ey = {0};
int n, m, ans[N];

int dist(const vector<int>& e, int x) {
  return upper_bound(e.begin(), e.end(), x) - e.begin() - 1;
}

struct KDN {
  set<int> a;
  int w, xl, xr, yl, yr;
  bool sx;
  bool leaf = true;
  KDN *lt = nullptr, *ge = nullptr;
} root;

void ds_split(KDN& d) {
  d.xr = d.yr = 0;
  d.xl = d.yl = N;
  for (int i : d.a) {
    d.xl = min(d.xl, s[i].x);
    d.yl = min(d.yl, s[i].y);
    d.xr = max(d.xr, s[i].x);
    d.yr = max(d.yr, s[i].y);
    //cerr << i << ",";
  }
  //cerr << endl;

  int sz = d.a.size();
  if ((d.xr == d.xl && d.yr == d.yl) || sz < 19) {
    d.leaf = true;
    return;
  }

  d.lt = new KDN;
  d.ge = new KDN;

  vector<pair<int, int>> p;
  d.sx = d.xr - d.xl > d.yr - d.yl;
  if (d.sx) {
    for (int i : d.a)
      p.emplace_back(s[i].x, i);
    auto sp = p.begin() + (sz+1)/2;
    nth_element(p.begin(), sp, p.end());
    d.w = sp->first;
    if (d.xl == d.w) ++d.w;
    for (int i : d.a)
      if (s[i].x < d.w) {
        d.lt->a.insert(i);
      } else {
        d.ge->a.insert(i);
      }
  } else {
    for (int i : d.a)
      p.emplace_back(s[i].y, i);
    auto sp = p.begin() + (sz+1)/2;
    nth_element(p.begin(), sp, p.end());
    d.w = sp->first;
    if (d.yl == d.w) ++d.w;
    for (int i : d.a)
      if (s[i].y < d.w) {
        d.lt->a.insert(i);
      } else {
        d.ge->a.insert(i);
      }
  }

  if (d.lt->a.empty()) {
    delete d.lt;
    d.lt = nullptr;
  } else ds_split(*d.lt);

  if (d.ge->a.empty()) {
    delete d.ge;
    d.ge = nullptr;
  } else ds_split(*d.ge);
}

void ds_build() {
  for (int i = 0; i < m; ++i) {
    root.a.insert(i);
  }
  ds_split(root);
}

int ds_fn(const KDN& d, const P& p) {
  if (d.a.empty()) return m;

  if (p.xl > d.xr || p.xr < d.xl || p.yl > d.yr || p.yr < d.yl) return m;

  if (p.xl <= d.xl && d.xr <= p.xr && p.yl <= d.yl && d.yr <= p.yr) {
    return *d.a.begin();
  }

  if (d.leaf) {
    for (int i : d.a) {
      if (p.xl <= s[i].x && s[i].x <= p.xr &&
        p.yl <= s[i].y && s[i].y <= p.yr) {
          return i;
        }
    }
    return m;
  }

  int ans = m;
  if (d.lt) ans = min(ans, ds_fn(*d.lt, p));
  if (d.ge) ans = min(ans, ds_fn(*d.ge, p));
  return ans;
}

int ds_findmin(const P& p) {
  return ds_fn(root, p);
}

void ds_remove(int i) {
  KDN* p = &root;
  while (p) {
    p->a.erase(i);
    if (p->leaf) break;
    bool use_lt = true;
    if (p->sx && s[i].x >= p->w) use_lt = false;
    if (!p->sx && s[i].y >= p->w) use_lt = false;
    p = use_lt ? p->lt : p->ge;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int xl, xr, yl, yr, z;
    scanf("%d%d%d%d%d", &xl, &xr, &yl, &yr, &z);
    a[i].xl = xl;
    a[i].xr = xr;
    a[i].yl = yl;
    a[i].yr = yr;
    a[i].z = z;
    a[i].id = i + 1;
    ex.push_back(xl);
    ex.push_back(xr + 1);
    ey.push_back(yl);
    ey.push_back(yr + 1);
  }
  sort(ex.begin(), ex.end());
  ex.resize(unique(ex.begin(), ex.end()) - ex.begin());
  sort(ey.begin(), ey.end());
  ey.resize(unique(ey.begin(), ey.end()) - ey.begin());
  for (int i = 0; i < n; ++i) {
    a[i].xl = dist(ex, a[i].xl);
    a[i].xr = dist(ex, a[i].xr);
    a[i].yl = dist(ey, a[i].yl);
    a[i].yr = dist(ey, a[i].yr);
  }
  scanf("%d", &m);
  for (int i = 0, x, y; i < m; ++i) {
    scanf("%d%d", &x, &y);
    s[i].x = dist(ex, x);
    s[i].y = dist(ey, y);
  }
  ds_build();
  sort(a, a + n);
  for (const P& p : a) {
    int x = ds_findmin(p);
    if (x < m) {
      ans[x] = p.id;
      ds_remove(x);
    }
  }

  for (int i = 0; i < m; ++i) printf("%d\n", ans[i]);
}


#include <bits/stdc++.h>
using namespace std;

const int N = 2.1e5;

struct P {
  int xl, xr, yl, yr, z, id;
  bool operator<(const P& o) const {
    return z < o.z;
  }
} a[N];

struct S {
  int x, y;
} s[N];

vector<int> ex = {0}, ey = {0};
int n, m, nx, ny, ans[N];

int dist(const vector<int>& e, int x) {
  return upper_bound(e.begin(), e.end(), x) - e.begin() - 1;
}

struct KDN {
  set<int> a;
  int w, xl, xr, yl, yr;
  bool sx;
  bool leaf = true;
  KDN *lt = nullptr, *ge = nullptr;
} root;

void ds_split(KDN& d) {
  d.xr = d.yr = 0;
  d.xl = d.yl = N;
  for (int i : d.a) {
    d.xl = min(d.xl, s[i].x);
    d.yl = min(d.yl, s[i].y);
    d.xr = max(d.xr, s[i].x);
    d.yr = max(d.yr, s[i].y);
    //cerr << i << ",";
  }
  //cerr << endl;

  int sz = d.a.size();
  if ((d.xr == d.xl && d.yr == d.yl) || sz < 9) {
    d.leaf = true;
    return;
  }

  d.lt = new KDN;
  d.ge = new KDN;

  vector<pair<int, int>> p;
  d.sx = d.xr - d.xl > d.yr - d.yl;
  if (d.sx) {
    for (int i : d.a)
      p.emplace_back(s[i].x, i);
    auto sp = p.begin() + (sz+1)/2;
    nth_element(p.begin(), sp, p.end());
    d.w = sp->first;
    for (int i : d.a)
      if (s[i].x < d.w) {
        d.lt->a.insert(i);
      } else {
        d.ge->a.insert(i);
      }
  } else {
    for (int i : d.a)
      p.emplace_back(s[i].y, i);
    auto sp = p.begin() + (sz+1)/2;
    nth_element(p.begin(), sp, p.end());
    d.w = sp->first;
    for (int i : d.a)
      if (s[i].y < d.w) {
        d.lt->a.insert(i);
      } else {
        d.ge->a.insert(i);
      }
  }

  if (d.lt->a.empty()) {
    delete d.lt;
    d.lt = nullptr;
  } else ds_split(*d.lt);

  if (d.ge->a.empty()) {
    delete d.ge;
    d.ge = nullptr;
  } else ds_split(*d.ge);
}

void ds_build() {
  for (int i = 0; i < m; ++i) {
    root.a.insert(i);
  }
  ds_split(root);
}

int ds_fn(const KDN& d, const P& p) {
  if (d.a.empty()) return m;

  if (p.xl > d.xr || p.xr < d.xl || p.yl > d.yr || p.yr < d.yl) return m;

  if (p.xl <= d.xl && d.xr <= p.xr && p.yl <= d.yl && d.yr <= p.yr) {
    return *d.a.rbegin();
  }

  if (d.leaf) {
    for (int i : d.a) {
      if (p.xl <= s[i].x && s[i].x <= p.xr &&
        p.yl <= s[i].y && s[i].y <= p.yr) {
          return i;
        }
    }
    return m;
  }

  int ans = m;
  if (d.lt) ans = min(ans, ds_fn(*d.lt, p));
  if (d.ge) ans = min(ans, ds_fn(*d.ge, p));
  return ans;
}

int ds_findmin(const P& p) {
  return ds_fn(root, p);
}

void ds_remove(int i) {
  KDN* p = &root;
  while (p) {
    p->a.erase(i);
    if (p->leaf) break;
    bool use_lt = true;
    if (p->sx && s[i].x >= p->w) use_lt = false;
    if (!p->sx && s[i].y >= p->w) use_lt = false;
    p = use_lt ? p->lt : p->ge;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int xl, xr, yl, yr, z;
    scanf("%d%d%d%d%d", &xl, &xr, &yl, &yr, &z);
    a[i].xl = xl;
    a[i].xr = xr;
    a[i].yl = yl;
    a[i].yr = yr;
    a[i].z = z;
    a[i].id = i + 1;
    ex.push_back(xl);
    ex.push_back(xr + 1);
    ey.push_back(yl);
    ey.push_back(yr + 1);
  }
  sort(ex.begin(), ex.end());
  ex.resize(unique(ex.begin(), ex.end()) - ex.begin());
  sort(ey.begin(), ey.end());
  ey.resize(unique(ey.begin(), ey.end()) - ey.begin());
  for (int i = 0; i < n; ++i) {
    a[i].xl = dist(ex, a[i].xl);
    a[i].xr = dist(ex, a[i].xr);
    a[i].yl = dist(ey, a[i].yl);
    a[i].yr = dist(ey, a[i].yr);
  }
  scanf("%d", &m);
  for (int i = 0, x, y; i < m; ++i) {
    scanf("%d%d", &x, &y);
    s[i].x = dist(ex, x);
    s[i].y = dist(ey, y);
  }
  ds_build();
  sort(a, a + n);
  for (const P& p : a) {
    int x = ds_findmin(p);
    if (x < m) {
      ans[x] = p.id;
      ds_remove(x);
    }
  }

  for (int i = 0; i < m; ++i) printf("%d\n", ans[i]);
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1.1e5;
int n, m;
struct P {
    int xl, xr, yl, yr, z, id;
    bool operator<(const P& o) const {
        return z < o.z;
    }
} a[N];
struct S { int x, y; } b[N];

struct Node {
    int l, r, h, v;
    int yl, yr, mi;
} T[N * 18];
int top, f[N], g[N];

vector<int> ex;
int ans[N], nx;

void mt(int rt) {
  if (rt) {
    T[rt].yl = min(T[T[rt].l].yl, b[T[rt].v].y);
    T[rt].yr = max(T[T[rt].r].yr, b[T[rt].v].y);
    T[rt].mi = min(T[rt].v, min(T[T[rt].l].mi, T[T[rt].r].mi));
  }
}
void dbg(int rt, int lv = 0) {
  if (!lv) cerr << "----\n";
  if (!rt) return;
  dbg(T[rt].l, lv + 1);
  for (int i = 0; i < lv; ++i) cerr << "  ";
  cerr << T[rt].v << endl;
  dbg(T[rt].r, lv + 1);
}
int splt(int rt, int*l, int*r, int i) {
  if (!rt) return *l = *r = 0;
  if (b[T[rt].v].y < b[i].y || (b[T[rt].v].y == b[i].y && T[rt].v < i)) {
    int res = splt(T[rt].r, l, r, i);
    T[rt].r = *l;
    mt(*l = rt);
    return res;
  }
  int res = splt(T[rt].l, l, r, i);
  if (res) {
    T[rt].l = *r;
    mt(*r = rt);
    return res;
  }
  *r = T[rt].r;
  T[rt].l = T[rt].r = 0;
  mt(rt);
  return rt;
}
int mrg(int l, int r) {
  if (!l || !r) return l + r;
  if (T[l].h > T[r].h) {
    T[l].r = mrg(T[l].r, r);
    mt(l);
    return l;
  }
  T[r].l = mrg(l, T[r].l);
  mt(r);
  return r;
}

void ins2(int *rt, int i) {
  int l, r;
  *rt = splt(*rt, &l, &r, i);
  T[++top].v = i;
  T[top].h = rand();
  mt(top);
  *rt = mrg(l, mrg(top, mrg(*rt, r)));
}
void del2(int *rt, int i) {
  int l, r;
  *rt = splt(*rt, &l, &r, i);
  *rt = mrg(l, r);
}
int fnd2(int rt, int l, int r) {
  if (T[rt].yl > r || T[rt].yr < l) return m;
  if (l <= T[rt].yl && T[rt].yr <= r) return T[rt].mi;
  int res = min(fnd2(T[rt].l, l, r), fnd2(T[rt].r, l, r));
  int y = b[T[rt].v].y;
  if (l <= y && y <= r) res = min(res, T[rt].v);
  return res;
}

void ins(int i) {
  int x = b[i].x + 1;
  if (x % 2 == 0) ins2(&g[x], i);
  while (x <= nx) {
    ins2(&f[x], i);
    x += x&-x;
  }
}
void del(int i) {
  int x = b[i].x + 1;
  if (x % 2 == 0) del2(&g[x], i);
  while (x <= nx) {
    del2(&f[x], i);
    x += x&-x;
  }
}
int fnd(const P& p) {
  int x = p.xr;
  int ans = m;
  //cerr << "fnd\n";
  while (x > p.xl) {
    if ((x&x-1) >= p.xl) {
      //dbg(f[x]);
      ans = min(ans, fnd2(f[x], p.yl, p.yr));
      x &= x - 1;
    } else {
      //dbg(g[x]);
      ans = min(ans, fnd2(g[x], p.yl, p.yr));
      --x;
    }
  }
  //cerr << "returns " << ans << endl << endl;
  return ans;
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d%d%d%d", &a[i].xl, &a[i].xr, &a[i].yl, &a[i].yr, &a[i].z);
        a[i].id = i + 1;
    }
    sort(a, a + n);
    scanf("%d", &m);
    for (int i = 0; i < m; ++i) {
        scanf("%d%d", &b[i].x, &b[i].y);
        ex.push_back(b[i].x);
    }
    sort(ex.begin(), ex.end());
    ex.resize(unique(ex.begin(), ex.end()) - ex.begin());
    nx = ex.size();

    srand(950516);
    T[0].mi = m;
    T[0].yl = 1e8;
    T[0].yr = -1e8;
    for (int i = 0; i < m; ++i) {
        b[i].x = lower_bound(ex.begin(), ex.end(), b[i].x) - ex.begin();
        ins(i);
    }

    //for (int i = 1; i <= nx; ++i) {
      //cerr << ">> " << i << endl;
      //dbg(i%2?f[i]:g[i]);
      //dbg(f[i]);
    //}

    for (int i = 0; i < n; ++i) {
        auto& p = a[i];
        p.xl = lower_bound(ex.begin(), ex.end(), p.xl) - ex.begin();
        p.xr = upper_bound(ex.begin(), ex.end(), p.xr) - ex.begin();
        int x = fnd(p);
        if (x < m) {
            ans[x] = p.id;
            del(x);
        }
    }
    for (int i = 0; i < m; ++i) printf("%d\n", ans[i]);
}


// 5:21 - 5:48 - re sample
//      - 5:51 - pass sample - wa 26
#include <algorithm>
#include <cassert>
#include <unordered_map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits>
#include <memory>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) static_cast<int>((a).size())
#define fillchar(a, x) memset(a, x, sizeof(a))
#define rep(i, a, b) for(int i=int(a); i<=int(b); ++i)
#define irep(i, a, b) for(int i=int(a); i>=int(b); --i)
#define replr(i, a, b) rep(i, a, (b)-1)
#define reprl(i, a, b) irep(i, (b)-1, a)
#define repn(i, n) rep(i, 0, (n)-1)
#define irepn(i, n) irep(i, (n)-1, 0)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<string> VS;
template<class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& v) { return os<<"("<<v.first<<", "<<v.second<<")"; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { os<<"["; repn(i, sz(v)) { if(i) os<<", "; os<<v[i]; } return os<<"]"; }
template<class T> bool setmax(T &_a, T _b) { if(_b>_a) { _a=_b; return true; } return false; }
template<class T> bool setmin(T &_a, T _b) { if(_b<_a) { _a=_b; return true; } return false; }
template<class T> T gcd(T _a, T _b) { return _b==0?_a:gcd(_b,_a%_b); }

int kInfX, kInfY;

void update(int& a, int b) {
    if(a<0) a=b;
    else {
        if(b>=0) setmin(a, b);
    }
}

struct Tree {
    struct Node {
        int v=-1;
        Node *l=nullptr, *r=nullptr;
    } *root;

    Tree() : root(nullptr) {}

    int minval(Node* cur, int l, int r, int s, int t) const {
        if(cur==nullptr) return -1;
        if(s<=l && r<=t) return cur->v;
        const int m=(l+r)/2;
        int ans=-1;
        if(s<m) update(ans, minval(cur->l, l, m, s, t));
        if(m<t) update(ans, minval(cur->r, m, r, s, t));
        return ans;
    }

    int minval(int s, int t) const {
        return minval(root, 0, kInfY, s, t);
    }

    Node* change(Node* cur, int l, int r, int i, int v) {
        if(cur==nullptr) cur=new Node();
        if(l+1==r) { cur->v=v; return cur; }
        const int m=(l+r)/2;
        if(i<m) cur->l=change(cur->l, l, m, i, v);
            else cur->r=change(cur->r, m, r, i, v);
        cur->v=-1;
        if(cur->l) update(cur->v, cur->l->v);
        if(cur->r) update(cur->v, cur->r->v);
        return cur;
    }

    void change(int i, int v) {
        root=change(root, 0, kInfY, i, v);
    }
};

struct BigTree {
    struct Node {
        Tree tree;
        unordered_map<int, set<int>> a;
        Node *l=nullptr, *r=nullptr;
    } *root;

    BigTree() : root(nullptr) {}

    int minval(Node* cur, int l, int r, int x1, int x2, int y1, int y2) const {
        if(cur==nullptr) return -1;
        if(x1<=l && r<=x2) return cur->tree.minval(y1, y2);
        const int m=(l+r)/2;
        int ans=-1;
        if(x1<m) update(ans, minval(cur->l, l, m, x1, x2, y1, y2));
        if(m<x2) update(ans, minval(cur->r, m, r, x1, x2, y1, y2));
        return ans;
    }

    int minval(int x1, int x2, int y1, int y2) const {
        return minval(root, 0, kInfX, x1, x2, y1, y2);
    }

    Node* erase(Node* cur, int l, int r, int x, int y, int v) {
        if(cur==nullptr) cur=new Node();
        {
            cur->a[y].erase(v);
            if(cur->a[y].empty()) {
                cur->tree.change(y, -1);
            } else {
                cur->tree.change(y, *cur->a[y].begin());
            }
        }
        if(l+1==r) return cur;
        const int m=(l+r)/2;
        if(x<m) cur->l=erase(cur->l, l, m, x, y, v);
            else cur->r=erase(cur->r, m, r, x, y, v);
        return cur;
    }

    void erase(int x, int y, int v) {
        root=erase(root, 0, kInfX, x, y, v);
    }

    Node* insert(Node* cur, int l, int r, int x, int y, int v) {
        if(cur==nullptr) cur=new Node();
        {
            cur->a[y].insert(v);
            cur->tree.change(y, *cur->a[y].begin());
        }
        if(l+1==r) return cur;
        const int m=(l+r)/2;
        if(x<m) cur->l=insert(cur->l, l, m, x, y, v);
            else cur->r=insert(cur->r, m, r, x, y, v);
        return cur;
    }

    void insert(int x, int y, int v) {
        root=insert(root, 0, kInfX, x, y, v);
    }
};

int main() {
    struct Target { int x1, x2, y1, y2, z, i; };
    int n; scanf("%d",&n);
    vector<Target> ts(n);
    repn(i, n) {
        scanf("%d%d%d%d%d", &ts[i].x1,&ts[i].x2,&ts[i].y1,&ts[i].y2,&ts[i].z);
        ts[i].i=i;
    }

    int m; scanf("%d", &m);
    vector<PII> bs(m);
    repn(i, m) scanf("%d%d", &bs[i].fi,&bs[i].se);

    {
        VI xs;
        for(const auto& t: ts) xs.pb(t.x1), xs.pb(t.x2);
        for(const auto& b: bs) xs.pb(b.fi);
        sort(all(xs)), xs.erase(unique(all(xs)), xs.end());
        kInfX=sz(xs);
        for(auto& t: ts) {
            t.x1=int(lower_bound(all(xs), t.x1)-xs.begin());
            t.x2=int(lower_bound(all(xs), t.x2)-xs.begin());
        }
        for(auto& b: bs) b.fi=int(lower_bound(all(xs), b.fi)-xs.begin());
    }
    {
        VI ys;
        for(const auto& t: ts) ys.pb(t.y1), ys.pb(t.y2);
        for(const auto& b: bs) ys.pb(b.se);
        sort(all(ys)), ys.erase(unique(all(ys)), ys.end());
        kInfY=sz(ys);
        for(auto& t: ts) {
            t.y1=int(lower_bound(all(ys), t.y1)-ys.begin());
            t.y2=int(lower_bound(all(ys), t.y2)-ys.begin());
        }
        for(auto& b: bs) b.se=int(lower_bound(all(ys), b.se)-ys.begin());
    }

    BigTree tr;
    repn(i, m) tr.insert(bs[i].fi, bs[i].se, i);

    VI ans(m, -1);
    sort(all(ts), [](const Target& a, const Target& b) { return a.z<b.z; });
    for(const auto& t: ts) {
        int i=tr.minval(t.x1, t.x2+1, t.y1, t.y2+1);
        if(i<0) continue;
        ans[i]=t.i;
        tr.erase(bs[i].fi, bs[i].se, i);
    }
    for(int i: ans) printf("%d\n", i+1);

    return 0;
}


#include <algorithm>
#include <cassert>
#include <unordered_map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits>
#include <memory>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) static_cast<int>((a).size())
#define fillchar(a, x) memset(a, x, sizeof(a))
#define rep(i, a, b) for(int i=int(a); i<=int(b); ++i)
#define irep(i, a, b) for(int i=int(a); i>=int(b); --i)
#define replr(i, a, b) rep(i, a, (b)-1)
#define reprl(i, a, b) irep(i, (b)-1, a)
#define repn(i, n) rep(i, 0, (n)-1)
#define irepn(i, n) irep(i, (n)-1, 0)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<string> VS;
template<class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& v) { return os<<"("<<v.first<<", "<<v.second<<")"; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { os<<"["; repn(i, sz(v)) { if(i) os<<", "; os<<v[i]; } return os<<"]"; }
template<class T> bool setmax(T &_a, T _b) { if(_b>_a) { _a=_b; return true; } return false; }
template<class T> bool setmin(T &_a, T _b) { if(_b<_a) { _a=_b; return true; } return false; }
template<class T> T gcd(T _a, T _b) { return _b==0?_a:gcd(_b,_a%_b); }

const int kInf=1<<30;

int kInfX ;

struct Tree {
    const int n;
    VI tr;

    Tree(int _n) : n(_n), tr(n*4, kInf) {}

    int minval(int cur, int l, int r, int s, int t) const {
        if(s<=l && r<=t) return tr[cur];
        const int m=(l+r)/2;
        int ans=kInf;
        if(s<m) setmin(ans, minval(cur*2+1, l, m, s, t));
        if(m<t) setmin(ans, minval(cur*2+2, m, r, s, t));
        return ans;
    }

    int minval(int s, int t) const {
        auto r=minval(0, 0, n, s, t);
        return r;
    }

    void change(int cur, int l, int r, int i, int v) {
        if(l+1==r) { tr[cur]=v; return; }
        const int m=(l+r)/2;
        if(i<m) change(cur*2+1, l, m, i, v);
           else change(cur*2+2, m, r, i, v);
        tr[cur]=min(tr[cur*2+1], tr[cur*2+2]);
    }

    void change(int i, int v) {
        change(0, 0, n, i, v);
    }
};

struct BigTree {
    struct Node {
        VI ys;
        vector<set<int>> ps;
        Tree* tree;
        Node *l=nullptr, *r=nullptr;
        int yi(int y) const { return int(lower_bound(all(ys), y)-ys.begin()); }
    } *root;

    static VI grab_ys(const vector<pair<PII, int>>& ps) {
        VI ys;
        for(const auto& p: ps) ys.pb(p.fi.se);
        sort(all(ys)), ys.erase(unique(all(ys)), ys.end());
        return ys;
    }

    Node* build(int l, int r, const vector<pair<PII, int>>& ps) {
        if(ps.empty()) return nullptr;
        Node* cur=new Node();
        cur->ys=grab_ys(ps);
        cur->ps.resize(cur->ys.size());
        for(const auto& p: ps) cur->ps[cur->yi(p.fi.se)].insert(p.se);
        cur->tree=new Tree(sz(cur->ys));
        repn(i, sz(cur->ys)) cur->tree->change(i, *cur->ps[i].begin());
        if(l+1<r) {
            const int m=(l+r)/2;
            vector<pair<PII, int>> lps, rps;
            for(const auto& p: ps) (p.fi.fi<m?lps:rps).pb(p);
            cur->l=build(l, m, lps);
            cur->r=build(m, r, rps);
        }
        return cur;
    }

    BigTree(const VPI& ps) {
        vector<pair<PII, int>> tmp;
        repn(i, sz(ps)) tmp.pb(mp(ps[i], i));
        root=build(0, kInfX, tmp);
    }

    int minval(Node* cur, int l, int r, int x1, int x2, int y1, int y2) const {
        if(cur==nullptr) return kInf;
        if(x1<=l && r<=x2) return cur->tree->minval(cur->yi(y1), cur->yi(y2));
        const int m=(l+r)/2;
        int ans=kInf;
        if(x1<m) setmin(ans, minval(cur->l, l, m, x1, x2, y1, y2));
        if(m<x2) setmin(ans, minval(cur->r, m, r, x1, x2, y1, y2));
        return ans;
    }

    int minval(int x1, int x2, int y1, int y2) const {
        return minval(root, 0, kInfX, x1, x2, y1, y2);
    }

    Node* erase(Node* cur, int l, int r, int x, int y, int v) {
        if(cur==nullptr) return nullptr;
        {
            int i=cur->yi(y);
            cur->ps[i].erase(v);
            if(cur->ps[i].empty()) {
                cur->tree->change(i, kInf);
            } else {
                cur->tree->change(i, *cur->ps[i].begin());
            }
        }
        if(l+1==r) return cur;
        const int m=(l+r)/2;
        if(x<m) cur->l=erase(cur->l, l, m, x, y, v);
            else cur->r=erase(cur->r, m, r, x, y, v);
        return cur;
    }

    void erase(int x, int y, int v) {
        root=erase(root, 0, kInfX, x, y, v);
    }
};

int main() {
    struct Target { int x1, x2, y1, y2, z, i; };
    int n; scanf("%d",&n);
    vector<Target> ts(n);
    repn(i, n) {
        scanf("%d%d%d%d%d", &ts[i].x1,&ts[i].x2,&ts[i].y1,&ts[i].y2,&ts[i].z);
        ts[i].i=i;
    }

    int m; scanf("%d", &m);
    vector<PII> bs(m);
    repn(i, m) scanf("%d%d", &bs[i].fi,&bs[i].se);

    {
        VI xs;
        for(const auto& t: ts) xs.pb(t.x1), xs.pb(t.x2);
        for(const auto& b: bs) xs.pb(b.fi);
        sort(all(xs)), xs.erase(unique(all(xs)), xs.end());
        kInfX=sz(xs);
        for(auto& t: ts) {
            t.x1=int(lower_bound(all(xs), t.x1)-xs.begin());
            t.x2=int(lower_bound(all(xs), t.x2)-xs.begin());
        }
        for(auto& b: bs) b.fi=int(lower_bound(all(xs), b.fi)-xs.begin());
    }

    BigTree tr(bs);

    VI ans(m, kInf);
    sort(all(ts), [](const Target& a, const Target& b) { return a.z<b.z; });
    for(const auto& t: ts) {
        int i=tr.minval(t.x1, t.x2+1, t.y1, t.y2+1);
        if(i==kInf) continue;
        ans[i]=t.i;
        tr.erase(bs[i].fi, bs[i].se, i);
    }
    for(int i: ans) printf("%d\n", i==kInf ? 0 : i+1);

    return 0;
}


// 5:21 - 5:48 - re sample
//      - 5:51 - pass sample - wa 26
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits>
#include <memory>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) static_cast<int>((a).size())
#define fillchar(a, x) memset(a, x, sizeof(a))
#define rep(i, a, b) for(int i=int(a); i<=int(b); ++i)
#define irep(i, a, b) for(int i=int(a); i>=int(b); --i)
#define replr(i, a, b) rep(i, a, (b)-1)
#define reprl(i, a, b) irep(i, (b)-1, a)
#define repn(i, n) rep(i, 0, (n)-1)
#define irepn(i, n) irep(i, (n)-1, 0)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<string> VS;
template<class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& v) { return os<<"("<<v.first<<", "<<v.second<<")"; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { os<<"["; repn(i, sz(v)) { if(i) os<<", "; os<<v[i]; } return os<<"]"; }
template<class T> bool setmax(T &_a, T _b) { if(_b>_a) { _a=_b; return true; } return false; }
template<class T> bool setmin(T &_a, T _b) { if(_b<_a) { _a=_b; return true; } return false; }
template<class T> T gcd(T _a, T _b) { return _b==0?_a:gcd(_b,_a%_b); }

const int kInf=int(1e7)+1;

vector<bool> used;

void update(int& a, int b) {
    if(a<0) a=b;
    else {
        if(b>=0) setmin(a, b);
    }
}

struct Tree {
    struct Node {
        VI a;
        Node *l, *r;
    } *root;

    Node* build(int l, int r, const VPI& a) {
        if(a.empty()) return nullptr;
        const int m=(l+r)/2;
        Node* cur=new Node();

        cur->a.clear();
        for(const auto& p: a) cur->a.pb(p.se);
        sort(all(cur->a), greater<int>());

        if(l+1<r) {
            VPI la, ra;
            for(const auto& p: a) (p.fi<m?la:ra).pb(p);
            cur->l=build(l, m, la);
            cur->r=build(m, r, ra);
        } else {
            cur->l=cur->r=nullptr;
        }

        return cur;
    }

    Tree(const VPI& a) {
        root=build(0, kInf, a);
    }

    int minval(Node* cur, int l, int r, int s, int t) {
        if(cur==nullptr) return -1;
        if(s<=l && r<=t) {
            while(!cur->a.empty() && used[cur->a.back()]) cur->a.pop_back();
            if(cur->a.empty()) return -1;
            return cur->a.back();
        }
        const int m=(l+r)/2;
        int ans=-1;
        if(s<m) update(ans, minval(cur->l, l, m, s, t));
        if(m<t) update(ans, minval(cur->r, m, r, s, t));
        return ans;
    }

    int minval(int s, int t) {
        return minval(root, 0, kInf, s, t);
    }
};

struct BigTree {
    struct Node {
        Tree* tree;
        Node *l, *r;
    } *root;

    Node* build(int l, int r, const vector<pair<PII, int>>& ps) {
        if(ps.empty()) return nullptr;
        const int m=(l+r)/2;
        Node* cur=new Node();

        VPI ys;
        for(const auto& p: ps) ys.pb(mp(p.fi.se, p.se));
        cur->tree=new Tree(ys);

        if(l+1<r) {
            vector<pair<PII, int>> lps, rps;
            for(const auto& p: ps) (p.fi.fi<m?lps:rps).pb(p);
            cur->l=build(l, m, lps);
            cur->r=build(m, r, rps);
        } else {
            cur->l=cur->r=nullptr;
        }

        return cur;
    }

    BigTree(const vector<PII> &ps) {
        vector<pair<PII, int>> tmp;
        repn(i, sz(ps)) tmp.pb(mp(ps[i], i));
        root=build(0, kInf, tmp);
    }

    int minval(Node* cur, int l, int r, int x1, int x2, int y1, int y2) {
        //printf("%d %d %d %d %d %d\n",l,r,x1,x2,y1,y2);
        if(cur==nullptr) return -1;
        if(x1<=l && r<=x2) return cur->tree->minval(y1, y2);
        const int m=(l+r)/2;
        int ans=-1;
        if(x1<m) update(ans, minval(cur->l, l, m, x1, x2, y1, y2));
        if(m<x2) update(ans, minval(cur->r, m, r, x1, x2, y1, y2));
        return ans;
    }

    int minval(int x1, int x2, int y1, int y2) {
        return minval(root, 0, kInf, x1, x2, y1, y2);
    }
};

int main() {
    struct Target { int x1, x2, y1, y2, z, i; };
    int n; scanf("%d",&n);
    vector<Target> ts(n);
    repn(i, n) {
        scanf("%d%d%d%d%d", &ts[i].x1,&ts[i].x2,&ts[i].y1,&ts[i].y2,&ts[i].z);
        ts[i].i=i;
    }

    int m; scanf("%d", &m);
    vector<PII> bs(m);
    repn(i, m) scanf("%d%d", &bs[i].fi,&bs[i].se);
    BigTree tr(bs);

    used=vector<bool>(m, false);
    VI ans(m, -1);
    sort(all(ts), [](const Target& a, const Target& b) { return a.z<b.z; });
    for(const auto& t: ts) {
        int i=tr.minval(t.x1, t.x2+1, t.y1, t.y2+1);
        if(i<0) continue;
        used[i]=true, ans[i]=t.i;
    }
    for(int i: ans) printf("%d\n", i+1);

    return 0;
}


// 5:21 - 5:48 - re sample
//      - 5:51 - pass sample - wa 26
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits>
#include <memory>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) static_cast<int>((a).size())
#define fillchar(a, x) memset(a, x, sizeof(a))
#define rep(i, a, b) for(int i=int(a); i<=int(b); ++i)
#define irep(i, a, b) for(int i=int(a); i>=int(b); --i)
#define replr(i, a, b) rep(i, a, (b)-1)
#define reprl(i, a, b) irep(i, (b)-1, a)
#define repn(i, n) rep(i, 0, (n)-1)
#define irepn(i, n) irep(i, (n)-1, 0)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<string> VS;
template<class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& v) { return os<<"("<<v.first<<", "<<v.second<<")"; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { os<<"["; repn(i, sz(v)) { if(i) os<<", "; os<<v[i]; } return os<<"]"; }
template<class T> bool setmax(T &_a, T _b) { if(_b>_a) { _a=_b; return true; } return false; }
template<class T> bool setmin(T &_a, T _b) { if(_b<_a) { _a=_b; return true; } return false; }
template<class T> T gcd(T _a, T _b) { return _b==0?_a:gcd(_b,_a%_b); }

const int kInf=int(1e7)+1;

vector<bool> used;

void update(int& a, int b) {
    if(a<0) a=b;
    else {
        if(b>=0) setmin(a, b);
    }
}

struct Tree {
    struct Node {
        VI a;
        Node *l, *r;
    } *root;

    Node* build(int l, int r, const VPI& a) {
        if(a.empty()) return nullptr;
        const int m=(l+r)/2;
        Node* cur=new Node();

        cur->a.clear();
        cur->a.reserve(a.size());
        for(const auto& p: a) cur->a.pb(p.se);
        sort(all(cur->a), greater<int>());

        if(l+1<r) {
            VPI la, ra;
            for(const auto& p: a) (p.fi<m?la:ra).pb(p);
            cur->l=build(l, m, la);
            cur->r=build(m, r, ra);
        } else {
            cur->l=cur->r=nullptr;
        }

        return cur;
    }

    Tree(const VPI& a) {
        root=build(0, kInf, a);
    }

    int minval(Node* cur, int l, int r, int s, int t) {
        if(cur==nullptr) return -1;
        if(s<=l && r<=t) {
            while(!cur->a.empty() && used[cur->a.back()]) cur->a.pop_back();
            if(cur->a.empty()) return -1;
            return cur->a.back();
        }
        const int m=(l+r)/2;
        int ans=-1;
        if(s<m) update(ans, minval(cur->l, l, m, s, t));
        if(m<t) update(ans, minval(cur->r, m, r, s, t));
        return ans;
    }

    int minval(int s, int t) {
        return minval(root, 0, kInf, s, t);
    }
};

struct BigTree {
    struct Node {
        Tree* tree;
        Node *l, *r;
    } *root;

    Node* build(int l, int r, const vector<pair<PII, int>>& ps) {
        if(ps.empty()) return nullptr;
        const int m=(l+r)/2;
        Node* cur=new Node();

        VPI ys;
        for(const auto& p: ps) ys.pb(mp(p.fi.se, p.se));
        cur->tree=new Tree(ys);

        if(l+1<r) {
            vector<pair<PII, int>> lps, rps;
            for(const auto& p: ps) (p.fi.fi<m?lps:rps).pb(p);
            cur->l=build(l, m, lps);
            cur->r=build(m, r, rps);
        } else {
            cur->l=cur->r=nullptr;
        }

        return cur;
    }

    BigTree(const vector<PII> &ps) {
        vector<pair<PII, int>> tmp;
        repn(i, sz(ps)) tmp.pb(mp(ps[i], i));
        root=build(0, kInf, tmp);
    }

    int minval(Node* cur, int l, int r, int x1, int x2, int y1, int y2) {
        //printf("%d %d %d %d %d %d\n",l,r,x1,x2,y1,y2);
        if(cur==nullptr) return -1;
        if(x1<=l && r<=x2) return cur->tree->minval(y1, y2);
        const int m=(l+r)/2;
        int ans=-1;
        if(x1<m) update(ans, minval(cur->l, l, m, x1, x2, y1, y2));
        if(m<x2) update(ans, minval(cur->r, m, r, x1, x2, y1, y2));
        return ans;
    }

    int minval(int x1, int x2, int y1, int y2) {
        return minval(root, 0, kInf, x1, x2, y1, y2);
    }
};

int main() {
    struct Target { int x1, x2, y1, y2, z, i; };
    int n; scanf("%d",&n);
    vector<Target> ts(n);
    repn(i, n) {
        scanf("%d%d%d%d%d", &ts[i].x1,&ts[i].x2,&ts[i].y1,&ts[i].y2,&ts[i].z);
        ts[i].i=i;
    }

    int m; scanf("%d", &m);
    vector<PII> bs(m);
    repn(i, m) scanf("%d%d", &bs[i].fi,&bs[i].se);
    BigTree tr(bs);

    used=vector<bool>(m, false);
    VI ans(m, -1);
    sort(all(ts), [](const Target& a, const Target& b) { return a.z<b.z; });
    for(const auto& t: ts) {
        int i=tr.minval(t.x1, t.x2+1, t.y1, t.y2+1);
        if(i<0) continue;
        used[i]=true, ans[i]=t.i;
    }
    for(int i: ans) printf("%d\n", i+1);

    return 0;
}


// 5:21 - 5:48 - re sample
//      - 5:51 - pass sample - wa 26
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits>
#include <memory>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) static_cast<int>((a).size())
#define fillchar(a, x) memset(a, x, sizeof(a))
#define rep(i, a, b) for(int i=int(a); i<=int(b); ++i)
#define irep(i, a, b) for(int i=int(a); i>=int(b); --i)
#define replr(i, a, b) rep(i, a, (b)-1)
#define reprl(i, a, b) irep(i, (b)-1, a)
#define repn(i, n) rep(i, 0, (n)-1)
#define irepn(i, n) irep(i, (n)-1, 0)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<string> VS;
template<class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& v) { return os<<"("<<v.first<<", "<<v.second<<")"; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { os<<"["; repn(i, sz(v)) { if(i) os<<", "; os<<v[i]; } return os<<"]"; }
template<class T> bool setmax(T &_a, T _b) { if(_b>_a) { _a=_b; return true; } return false; }
template<class T> bool setmin(T &_a, T _b) { if(_b<_a) { _a=_b; return true; } return false; }
template<class T> T gcd(T _a, T _b) { return _b==0?_a:gcd(_b,_a%_b); }

int kInfX, kInfY;

vector<bool> used;

void update(int& a, int b) {
    if(a<0) a=b;
    else {
        if(b>=0) setmin(a, b);
    }
}

struct Tree {
    struct Node {
        VI a;
        Node *l, *r;
    } *root;

    Node* build(int l, int r, const VPI& a) {
        if(a.empty()) return nullptr;
        const int m=(l+r)/2;
        Node* cur=new Node();

        cur->a.clear();
        cur->a.reserve(a.size());
        for(const auto& p: a) cur->a.pb(p.se);
        sort(all(cur->a), greater<int>());

        if(l+1<r) {
            VPI la, ra;
            for(const auto& p: a) (p.fi<m?la:ra).pb(p);
            cur->l=build(l, m, la);
            cur->r=build(m, r, ra);
        } else {
            cur->l=cur->r=nullptr;
        }

        return cur;
    }

    Tree(const VPI& a) {
        root=build(0, kInfY, a);
    }

    int minval(Node* cur, int l, int r, int s, int t) {
        if(cur==nullptr) return -1;
        if(s<=l && r<=t) {
            while(!cur->a.empty() && used[cur->a.back()]) cur->a.pop_back();
            if(cur->a.empty()) return -1;
            return cur->a.back();
        }
        const int m=(l+r)/2;
        int ans=-1;
        if(s<m) update(ans, minval(cur->l, l, m, s, t));
        if(m<t) update(ans, minval(cur->r, m, r, s, t));
        return ans;
    }

    int minval(int s, int t) {
        return minval(root, 0, kInfY, s, t);
    }
};

struct BigTree {
    struct Node {
        Tree* tree;
        Node *l, *r;
    } *root;

    Node* build(int l, int r, const vector<pair<PII, int>>& ps) {
        if(ps.empty()) return nullptr;
        const int m=(l+r)/2;
        Node* cur=new Node();

        VPI ys;
        for(const auto& p: ps) ys.pb(mp(p.fi.se, p.se));
        cur->tree=new Tree(ys);

        if(l+1<r) {
            vector<pair<PII, int>> lps, rps;
            for(const auto& p: ps) (p.fi.fi<m?lps:rps).pb(p);
            cur->l=build(l, m, lps);
            cur->r=build(m, r, rps);
        } else {
            cur->l=cur->r=nullptr;
        }

        return cur;
    }

    BigTree(const vector<PII> &ps) {
        vector<pair<PII, int>> tmp;
        repn(i, sz(ps)) tmp.pb(mp(ps[i], i));
        root=build(0, kInfX, tmp);
    }

    int minval(Node* cur, int l, int r, int x1, int x2, int y1, int y2) {
        //printf("%d %d %d %d %d %d\n",l,r,x1,x2,y1,y2);
        if(cur==nullptr) return -1;
        if(x1<=l && r<=x2) return cur->tree->minval(y1, y2);
        const int m=(l+r)/2;
        int ans=-1;
        if(x1<m) update(ans, minval(cur->l, l, m, x1, x2, y1, y2));
        if(m<x2) update(ans, minval(cur->r, m, r, x1, x2, y1, y2));
        return ans;
    }

    int minval(int x1, int x2, int y1, int y2) {
        return minval(root, 0, kInfX, x1, x2, y1, y2);
    }
};

int main() {
    struct Target { int x1, x2, y1, y2, z, i; };
    int n; scanf("%d",&n);
    vector<Target> ts(n);
    repn(i, n) {
        scanf("%d%d%d%d%d", &ts[i].x1,&ts[i].x2,&ts[i].y1,&ts[i].y2,&ts[i].z);
        ts[i].i=i;
    }

    int m; scanf("%d", &m);
    vector<PII> bs(m);
    repn(i, m) scanf("%d%d", &bs[i].fi,&bs[i].se);

    {
        VI xs;
        for(const auto& t: ts) xs.pb(t.x1), xs.pb(t.x2);
        for(const auto& b: bs) xs.pb(b.fi);
        sort(all(xs)), xs.erase(unique(all(xs)), xs.end());
        kInfX=sz(xs);
        for(auto& t: ts) {
            t.x1=int(lower_bound(all(xs), t.x1)-xs.begin());
            t.x2=int(lower_bound(all(xs), t.x2)-xs.begin());
        }
        for(auto& b: bs) b.fi=int(lower_bound(all(xs), b.fi)-xs.begin());
    }
    {
        VI ys;
        for(const auto& t: ts) ys.pb(t.y1), ys.pb(t.y2);
        for(const auto& b: bs) ys.pb(b.se);
        sort(all(ys)), ys.erase(unique(all(ys)), ys.end());
        kInfY=sz(ys);
        for(auto& t: ts) {
            t.y1=int(lower_bound(all(ys), t.y1)-ys.begin());
            t.y2=int(lower_bound(all(ys), t.y2)-ys.begin());
        }
        for(auto& b: bs) b.se=int(lower_bound(all(ys), b.se)-ys.begin());
    }

    BigTree tr(bs);
    used=vector<bool>(m, false);
    VI ans(m, -1);
    sort(all(ts), [](const Target& a, const Target& b) { return a.z<b.z; });
    for(const auto& t: ts) {
        int i=tr.minval(t.x1, t.x2+1, t.y1, t.y2+1);
        if(i<0) continue;
        used[i]=true, ans[i]=t.i;
    }
    for(int i: ans) printf("%d\n", i+1);

    return 0;
}


#include <algorithm>
#include <cassert>
#include <unordered_map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits>
#include <memory>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) static_cast<int>((a).size())
#define fillchar(a, x) memset(a, x, sizeof(a))
#define rep(i, a, b) for(int i=int(a); i<=int(b); ++i)
#define irep(i, a, b) for(int i=int(a); i>=int(b); --i)
#define replr(i, a, b) rep(i, a, (b)-1)
#define reprl(i, a, b) irep(i, (b)-1, a)
#define repn(i, n) rep(i, 0, (n)-1)
#define irepn(i, n) irep(i, (n)-1, 0)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<string> VS;
template<class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& v) { return os<<"("<<v.first<<", "<<v.second<<")"; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { os<<"["; repn(i, sz(v)) { if(i) os<<", "; os<<v[i]; } return os<<"]"; }
template<class T> bool setmax(T &_a, T _b) { if(_b>_a) { _a=_b; return true; } return false; }
template<class T> bool setmin(T &_a, T _b) { if(_b<_a) { _a=_b; return true; } return false; }
template<class T> T gcd(T _a, T _b) { return _b==0?_a:gcd(_b,_a%_b); }

const int kInf=1<<30;

int kInfX ;

struct Tree {
    const int n;
    VI tr;

    Tree(int _n) : n(_n), tr(n*4, kInf) {}

    int minval(int cur, int l, int r, int s, int t) const {
        if(s<=l && r<=t) return tr[cur];
        const int m=(l+r)/2;
        int ans=kInf;
        if(s<m) setmin(ans, minval(cur*2+1, l, m, s, t));
        if(m<t) setmin(ans, minval(cur*2+2, m, r, s, t));
        return ans;
    }

    int minval(int s, int t) const {
        if(s>=t) return kInf;
        return minval(0, 0, n, s, t);
    }

    void change(int cur, int l, int r, int i, int v) {
        if(l+1==r) { tr[cur]=v; return; }
        const int m=(l+r)/2;
        if(i<m) change(cur*2+1, l, m, i, v);
           else change(cur*2+2, m, r, i, v);
        tr[cur]=min(tr[cur*2+1], tr[cur*2+2]);
    }

    void change(int i, int v) {
        change(0, 0, n, i, v);
    }
};

struct BigTree {
    struct Node {
        VI ys;
        vector<set<int>> ps;
        Tree* tree;
        Node *l=nullptr, *r=nullptr;
        int yi(int y) const { return int(lower_bound(all(ys), y)-ys.begin()); }
    } *root;

    static VI grab_ys(const vector<pair<PII, int>>& ps) {
        VI ys;
        for(const auto& p: ps) ys.pb(p.fi.se);
        sort(all(ys)), ys.erase(unique(all(ys)), ys.end());
        return ys;
    }

    Node* build(int l, int r, const vector<pair<PII, int>>& ps) {
        if(ps.empty()) return nullptr;
        Node* cur=new Node();
        cur->ys=grab_ys(ps);
        cur->ps.resize(cur->ys.size());
        for(const auto& p: ps) cur->ps[cur->yi(p.fi.se)].insert(p.se);
        cur->tree=new Tree(sz(cur->ys));
        repn(i, sz(cur->ys)) cur->tree->change(i, *cur->ps[i].begin());
        if(l+1<r) {
            const int m=(l+r)/2;
            vector<pair<PII, int>> lps, rps;
            for(const auto& p: ps) (p.fi.fi<m?lps:rps).pb(p);
            cur->l=build(l, m, lps);
            cur->r=build(m, r, rps);
        }
        return cur;
    }

    BigTree(const VPI& ps) {
        vector<pair<PII, int>> tmp;
        repn(i, sz(ps)) tmp.pb(mp(ps[i], i));
        root=build(0, kInfX, tmp);
    }

    int minval(Node* cur, int l, int r, int x1, int x2, int y1, int y2) const {
        if(cur==nullptr) return kInf;
        if(x1<=l && r<=x2) return cur->tree->minval(cur->yi(y1), cur->yi(y2));
        const int m=(l+r)/2;
        int ans=kInf;
        if(x1<m) setmin(ans, minval(cur->l, l, m, x1, x2, y1, y2));
        if(m<x2) setmin(ans, minval(cur->r, m, r, x1, x2, y1, y2));
        return ans;
    }

    int minval(int x1, int x2, int y1, int y2) const {
        return minval(root, 0, kInfX, x1, x2, y1, y2);
    }

    Node* erase(Node* cur, int l, int r, int x, int y, int v) {
        {
            int i=cur->yi(y);
            cur->ps[i].erase(v);
            if(cur->ps[i].empty()) {
                cur->tree->change(i, kInf);
            } else {
                cur->tree->change(i, *cur->ps[i].begin());
            }
        }
        if(l+1==r) return cur;
        const int m=(l+r)/2;
        if(x<m) cur->l=erase(cur->l, l, m, x, y, v);
           else cur->r=erase(cur->r, m, r, x, y, v);
        return cur;
    }

    void erase(int x, int y, int v) {
        root=erase(root, 0, kInfX, x, y, v);
    }
};

int main() {
    struct Target { int x1, x2, y1, y2, z, i; };
    int n; scanf("%d",&n);
    vector<Target> ts(n);
    repn(i, n) {
        scanf("%d%d%d%d%d", &ts[i].x1,&ts[i].x2,&ts[i].y1,&ts[i].y2,&ts[i].z);
        ts[i].i=i;
    }

    int m; scanf("%d", &m);
    vector<PII> bs(m);
    repn(i, m) scanf("%d%d", &bs[i].fi,&bs[i].se);

    {
        VI xs;
        for(const auto& t: ts) xs.pb(t.x1), xs.pb(t.x2);
        for(const auto& b: bs) xs.pb(b.fi);
        sort(all(xs)), xs.erase(unique(all(xs)), xs.end());
        kInfX=sz(xs);
        for(auto& t: ts) {
            t.x1=int(lower_bound(all(xs), t.x1)-xs.begin());
            t.x2=int(lower_bound(all(xs), t.x2)-xs.begin());
        }
        for(auto& b: bs) b.fi=int(lower_bound(all(xs), b.fi)-xs.begin());
    }

    BigTree tr(bs);

    VI ans(m, kInf);
    sort(all(ts), [](const Target& a, const Target& b) { return a.z<b.z; });
    for(const auto& t: ts) {
        int i=tr.minval(t.x1, t.x2+1, t.y1, t.y2+1);
        if(i==kInf) continue;
        ans[i]=t.i;
        tr.erase(bs[i].fi, bs[i].se, i);
    }
    for(int i: ans) printf("%d\n", i==kInf ? 0 : i+1);

    return 0;
}


// 5:21 - 5:48 - re sample
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits>
#include <memory>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) static_cast<int>((a).size())
#define fillchar(a, x) memset(a, x, sizeof(a))
#define rep(i, a, b) for(int i=int(a); i<=int(b); ++i)
#define irep(i, a, b) for(int i=int(a); i>=int(b); --i)
#define replr(i, a, b) rep(i, a, (b)-1)
#define reprl(i, a, b) irep(i, (b)-1, a)
#define repn(i, n) rep(i, 0, (n)-1)
#define irepn(i, n) irep(i, (n)-1, 0)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<string> VS;
template<class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& v) { return os<<"("<<v.first<<", "<<v.second<<")"; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { os<<"["; repn(i, sz(v)) { if(i) os<<", "; os<<v[i]; } return os<<"]"; }
template<class T> bool setmax(T &_a, T _b) { if(_b>_a) { _a=_b; return true; } return false; }
template<class T> bool setmin(T &_a, T _b) { if(_b<_a) { _a=_b; return true; } return false; }
template<class T> T gcd(T _a, T _b) { return _b==0?_a:gcd(_b,_a%_b); }

const int kInf=int(1e7)+1;

vector<bool> used;

void update(int& a, int b) {
    if(a<0) a=b;
    else {
        if(b>=0) setmin(a, b);
    }
}

struct Tree {
    struct Node {
        VI a;
        Node *l, *r;
    } *root;

    Node* build(int l, int r, const VPI& a) {
        if(a.empty()) return nullptr;
        const int m=(l+r)/2;
        Node* cur=new Node();

        cur->a.clear();
        for(const auto& p: a) cur->a.pb(p.se);
        sort(all(cur->a), greater<int>());

        if(l+1<r) {
            VPI la, ra;
            for(const auto& p: a) (p.fi<m?la:ra).pb(p);
            cur->l=build(l, m, la);
            cur->r=build(m, r, ra);
        } else {
            cur->l=cur->r=nullptr;
        }

        return cur;
    }

    Tree(const VPI& a) {
        root=build(0, kInf, a);
    }

    int minval(Node* cur, int l, int r, int s, int t) {
        if(cur==nullptr) return -1;
        if(s<=l && r<=t) {
            while(!cur->a.empty() && used[cur->a.back()]) cur->a.pop_back();
            if(cur->a.empty()) return -1;
            return cur->a.back();
        }
        const int m=(l+r)/2;
        int ans=-1;
        if(s<m) update(ans, minval(cur->l, l, m, s, t));
        if(m<t) update(ans, minval(cur->r, m, r, s, t));
        return ans;
    }

    int minval(int s, int t) {
        return minval(root, 0, kInf, s, t);
    }
};

struct BigTree {
    struct Node {
        Tree* tree;
        Node *l, *r;
    } *root;

    Node* build(int l, int r, const vector<pair<PII, int>>& ps) {
        if(ps.empty()) return nullptr;
        const int m=(l+r)/2;
        Node* cur=new Node();

        VPI ys;
        for(const auto& p: ps) ys.pb(mp(p.fi.se, p.se));
        cur->tree=new Tree(ys);

        if(l+1<r) {
            vector<pair<PII, int>> lps, rps;
            for(const auto& p: ps) (p.fi.fi<m?lps:rps).pb(p);
            cur->l=build(l, m, lps);
            cur->r=build(m, r, rps);
        } else {
            cur->l=cur->r=nullptr;
        }

        return cur;
    }

    BigTree(const vector<PII> &ps) {
        vector<pair<PII, int>> tmp;
        repn(i, sz(ps)) tmp.pb(mp(ps[i], i));
        root=build(0, kInf, tmp);
    }

    int minval(Node* cur, int l, int r, int x1, int x2, int y1, int y2) {
        //printf("%d %d %d %d %d %d\n",l,r,x1,x2,y1,y2);
        if(cur==nullptr) return -1;
        if(x1<=l && r<=x2) return cur->tree->minval(y1, y2);
        const int m=(l+r)/2;
        int ans=-1;
        if(x1<m) update(ans, minval(cur->l, l, m, x1, x2, y1, y2));
        if(m<x2) update(ans, minval(cur->r, m, r, x1, x2, y1, y2));
        return ans;
    }

    int minval(int x1, int x2, int y1, int y2) {
        return minval(root, 0, kInf, x1, x2, y1, y2);
    }
};

int main() {
    struct Target { int x1, x2, y1, y2, z, i; };
    int n; scanf("%d",&n);
    vector<Target> ts(n);
    repn(i, n) {
        scanf("%d%d%d%d%d", &ts[i].x1,&ts[i].x2,&ts[i].y1,&ts[i].y2,&ts[i].z);
        ts[i].i=i;
    }

    int m; scanf("%d", &m);
    vector<PII> bs(m);
    repn(i, m) scanf("%d%d", &bs[i].fi,&bs[i].se);
    BigTree tr(bs);

    used=vector<bool>(n, false);
    VI ans(m, -1);
    sort(all(ts), [](const Target& a, const Target& b) { return a.z<b.z; });
    for(const auto& t: ts) {
        int i=tr.minval(t.x1, t.x2+1, t.y1, t.y2+1);
        if(i<0) continue;
        used[i]=true, ans[i]=t.i;
    }
    for(int i: ans) printf("%d\n", i+1);

    return 0;
}


// 5:21 - 5:48 - re sample
//      - 5:51 - pass sample - wa 26
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits>
#include <memory>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) static_cast<int>((a).size())
#define fillchar(a, x) memset(a, x, sizeof(a))
#define rep(i, a, b) for(int i=int(a); i<=int(b); ++i)
#define irep(i, a, b) for(int i=int(a); i>=int(b); --i)
#define replr(i, a, b) rep(i, a, (b)-1)
#define reprl(i, a, b) irep(i, (b)-1, a)
#define repn(i, n) rep(i, 0, (n)-1)
#define irepn(i, n) irep(i, (n)-1, 0)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<string> VS;
template<class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& v) { return os<<"("<<v.first<<", "<<v.second<<")"; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { os<<"["; repn(i, sz(v)) { if(i) os<<", "; os<<v[i]; } return os<<"]"; }
template<class T> bool setmax(T &_a, T _b) { if(_b>_a) { _a=_b; return true; } return false; }
template<class T> bool setmin(T &_a, T _b) { if(_b<_a) { _a=_b; return true; } return false; }
template<class T> T gcd(T _a, T _b) { return _b==0?_a:gcd(_b,_a%_b); }

const int kInf=int(1e7)+2;

vector<bool> used;

void update(int& a, int b) {
    if(a<0) a=b;
    else {
        if(b>=0) setmin(a, b);
    }
}

struct Tree {
    struct Node {
        VI a;
        Node *l, *r;
    } *root;

    Node* build(int l, int r, const VPI& a) {
        if(a.empty()) return nullptr;
        const int m=(l+r)/2;
        Node* cur=new Node();

        cur->a.clear();
        for(const auto& p: a) cur->a.pb(p.se);
        sort(all(cur->a), greater<int>());

        if(l+1<r) {
            VPI la, ra;
            for(const auto& p: a) (p.fi<m?la:ra).pb(p);
            cur->l=build(l, m, la);
            cur->r=build(m, r, ra);
        } else {
            cur->l=cur->r=nullptr;
        }

        return cur;
    }

    Tree(const VPI& a) {
        root=build(0, kInf, a);
    }

    int minval(Node* cur, int l, int r, int s, int t) {
        if(cur==nullptr) return -1;
        if(s<=l && r<=t) {
            while(!cur->a.empty() && used[cur->a.back()]) cur->a.pop_back();
            if(cur->a.empty()) return -1;
            return cur->a.back();
        }
        const int m=(l+r)/2;
        int ans=-1;
        if(s<m) update(ans, minval(cur->l, l, m, s, t));
        if(m<t) update(ans, minval(cur->r, m, r, s, t));
        return ans;
    }

    int minval(int s, int t) {
        return minval(root, 0, kInf, s, t);
    }
};

struct BigTree {
    struct Node {
        Tree* tree;
        Node *l, *r;
    } *root;

    Node* build(int l, int r, const vector<pair<PII, int>>& ps) {
        if(ps.empty()) return nullptr;
        const int m=(l+r)/2;
        Node* cur=new Node();

        VPI ys;
        for(const auto& p: ps) ys.pb(mp(p.fi.se, p.se));
        cur->tree=new Tree(ys);

        if(l+1<r) {
            vector<pair<PII, int>> lps, rps;
            for(const auto& p: ps) (p.fi.fi<m?lps:rps).pb(p);
            cur->l=build(l, m, lps);
            cur->r=build(m, r, rps);
        } else {
            cur->l=cur->r=nullptr;
        }

        return cur;
    }

    BigTree(const vector<PII> &ps) {
        vector<pair<PII, int>> tmp;
        repn(i, sz(ps)) tmp.pb(mp(ps[i], i));
        root=build(0, kInf, tmp);
    }

    int minval(Node* cur, int l, int r, int x1, int x2, int y1, int y2) {
        //printf("%d %d %d %d %d %d\n",l,r,x1,x2,y1,y2);
        if(cur==nullptr) return -1;
        if(x1<=l && r<=x2) return cur->tree->minval(y1, y2);
        const int m=(l+r)/2;
        int ans=-1;
        if(x1<m) update(ans, minval(cur->l, l, m, x1, x2, y1, y2));
        if(m<x2) update(ans, minval(cur->r, m, r, x1, x2, y1, y2));
        return ans;
    }

    int minval(int x1, int x2, int y1, int y2) {
        return minval(root, 0, kInf, x1, x2, y1, y2);
    }
};

int main() {
    struct Target { int x1, x2, y1, y2, z, i; };
    int n; scanf("%d",&n);
    vector<Target> ts(n);
    repn(i, n) {
        scanf("%d%d%d%d%d", &ts[i].x1,&ts[i].x2,&ts[i].y1,&ts[i].y2,&ts[i].z);
        ts[i].i=i;
    }

    int m; scanf("%d", &m);
    vector<PII> bs(m);
    repn(i, m) scanf("%d%d", &bs[i].fi,&bs[i].se);
    BigTree tr(bs);

    used=vector<bool>(n, false);
    VI ans(m, -1);
    sort(all(ts), [](const Target& a, const Target& b) { return a.z<b.z; });
    for(const auto& t: ts) {
        int i=tr.minval(t.x1, t.x2+1, t.y1, t.y2+1);
        if(i<0) continue;
        used[i]=true, ans[i]=t.i;
    }
    for(int i: ans) printf("%d\n", i+1);

    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int nn=100005;
struct mrx{int x1,x2,y1,y2,z,p;}a[nn];
int n,m,l[nn],r[nn];
void read(int &x){
 char ch=getchar();for(;ch<48;ch=getchar());
 for(x=0;ch>=48;ch=getchar())x=x*10+ch-48;
}
inline bool cmp(const mrx &x,const mrx &y){
 return x.z<y.z;
}
int main(){
 read(n);
 for(int i=1;i<=n;++i){
  read(a[i].x1);read(a[i].x2);
  read(a[i].y1);read(a[i].y2);
  read(a[i].z);a[i].p=i;
 }
 sort(a+1,a+n+1,cmp);
 for(int i=1;i<=n;++i)l[i]=i-1,r[i]=i+1;
 r[0]=1;l[0]=n;r[n]=0;
 read(m);
 for(int i=1;i<=m;++i){
  int x,y,j=0;
  read(x);read(y);
  for(j=r[0];j;j=r[j])
   if(x>=a[j].x1&&x<=a[j].x2&&y>=a[j].y1&&y<=a[j].y2){
    r[l[j]]=r[j],l[r[j]]=l[j];
    break;
   }
  printf("%d\n",a[j].p);
 }
 return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string.h>
#include <limits.h>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

using namespace std;

const int VS=1e5+20,DIM=2;
int n;
int ps1[VS][DIM];
int ps[VS][DIM][DIM];
int od[DIM][VS],temp[VS];

struct kd {
    int vidx, key, mins;
    kd *l,*r,*p;
    kd(int k=0, int ke = 0):vidx(k), key(ke) { l=r=p=0; }
    void maintain() {
        mins = key;
        if (l) {
            mins = std::min(mins, l->mins);
        }
        if (r) {
            mins = std::min(mins, r->mins);
        }
    }
};

kd * root;
kd *nn[VS], *ns[VS];

inline int cmp (int * a,int *b) {
    for(int i=0;i<DIM;i++) {
        if(a[i]<b[i]) return -1;
        if(a[i]>b[i]) return 1;
    }
    return 0;
}

inline void assign(int *a,int *b) {
    for(int i=0;i<DIM;i++) a[i]=b[i];
}

inline int * min(int *a,int *b) {
    if(cmp(a,b)<0) return a;
    else return b;
}

inline int * max(int *a,int *b) {
    if(cmp(a,b)>0) return a;
    else return b;
}

inline void CoorConvert(int (*ps)[DIM],int *ps1) {
    for(int d=0;d<DIM;d++) {
        for(int idx=0;idx<DIM;idx++) {
            if(idx==d) ps[d][idx]=ps1[0];
            else if(idx==0) ps[d][idx]=ps1[d];
            else ps[d][idx]=ps1[idx];
        }
    }
}

void iniOd(int n) {
    for(int i=0;i<n;i++) CoorConvert(ps[i],ps1[i]);
    for(int i=0;i<DIM;i++) for(int v=1;v<=n;v++) od[i][v]=v;
    for(int i=0;i<DIM;i++)
        std::sort(od[i],od[i]+n,[i](int a,int b) {
            return cmp(ps[a][i],ps[b][i])<0;
        });
}

map<pair<int, int>, set<int> > mm;

kd* buildKd(int i,int j,int dep) {
    if(i>j) return 0;
    int dim=dep%DIM,mid=(i+j)>>1,tt=od[dim][mid],x,y;
    if(i!=j)
        for(int d=0;d<=DIM-1;d++) {
            if(d!=dim) {
                x=i,y=mid+1;
                for(int ele=i;ele<=j;ele++) {
                    int cur=od[d][ele];
                    if(cur!=tt) {
                        if(cmp(ps[cur][dim],ps[tt][dim])<=0) temp[x++]=cur;
                        else temp[y++]=cur;
                    }
                }
                temp[mid]=tt;
                for(int ele=i;ele<=j;ele++) od[d][ele]=temp[ele];
            }
        }
    kd *l=buildKd(i,mid-1,dep+1);
    kd *r=buildKd(mid+1,j,dep+1);
    kd *ret=new kd(tt, *(mm[ {ps1[tt][0], ps1[tt][1]} ].begin() ) ); ret->l=l,ret->r=r;
    nn[tt] = ret; ret->maintain();
    if(l) l->p=ret; if(r) r->p=ret;
    return ret;
}

int low[VS][DIM][DIM],up[VS][DIM][DIM];

void preprocess(kd *root,int dep) {
    if(!root) return ;
    int dim=dep%DIM;
    if(root->l) {
        int lvidx=root->l->vidx;
        for(int i=0;i<DIM;i++)
            assign(low[lvidx][i],low[root->vidx][i]),assign(up[lvidx][i],up[root->vidx][i]);
        assign(up[lvidx][dim],ps[root->vidx][dim]);
        preprocess(root->l,dep+1);
    }
    if(root->r) {
        int rvidx=root->r->vidx;
        for(int i=0;i<DIM;i++)
            assign(low[rvidx][i],low[root->vidx][i]),assign(up[rvidx][i],up[root->vidx][i]);
        assign(low[rvidx][dim],ps[root->vidx][dim]);
        preprocess(root->r,dep+1);
    }
}

inline int interType(kd *root,int (*p1)[DIM],int (*p2)[DIM]) {
    bool conta=1; bool seper=0; int vidx=root->vidx;
    for(int i=0;i<DIM;i++) {
        if(!(cmp(low[vidx][i],p1[i])>=0&&cmp(up[vidx][i],p2[i])<=0)) conta=0;
        if(cmp(max(low[vidx][i],p1[i]),min(up[vidx][i],p2[i]))>=0) seper=1;
    }
    if(conta) return 1;
    if(seper) return 3;
    return 2;
}

inline bool lieIn(kd *root,int (*p1)[DIM],int (*p2)[DIM]) {
    for(int i=0;i<DIM;i++) {
        if(cmp(ps[root->vidx][i],p1[i])<0||cmp(ps[root->vidx][i],p2[i])>0) return 0;
    }
    return 1;
}

void iniSearch() {
	if(root) {
        for(int d=0;d<DIM;d++) {
            for(int idx=0;idx<DIM;idx++) {
                low[root->vidx][d][idx]=INT_MIN;
                up[root->vidx][d][idx]=INT_MAX;
            }
        }
    }
}

void convSearRange(int (*p1)[DIM],int (*p2)[DIM],int *pp1,int *pp2) {
    for(int d=0;d<DIM;d++) {
        p1[d][0]=pp1[d],p2[d][0]=pp2[d];
        for(int idx=1;idx<DIM;idx++) {
            p1[d][idx]=INT_MIN,p2[d][idx]=INT_MAX;
        }
    }
}

int query(kd *root,int (*p1)[DIM],int (*p2)[DIM]) {
    if(!root) return INT_MAX;
    int res = INT_MAX;
    if(lieIn(root,p1,p2)) res = std::min(res, root->key);
    if(root->l) {
        int type=interType(root->l,p1,p2);
        if(type==1) res = std::min(res, root->l->mins);
        else if(type==2) res = std::min(res, query(root->l,p1,p2) );
    }
    if(root->r) {
        int type=interType(root->r,p1,p2);
        if(type==1) res = std::min(res, root->r->mins);
        else if(type==2) res = std::min(res, query(root->r,p1,p2) );
    }
    return res;
}

void update(kd *root, int vidx, int val) {
    kd *kk = nn[vidx];
    kk->key = val;
    while (kk) {
        kk->maintain();
        kk = kk->p;
    }
}

struct tar{
    int x1, x2, y1, y2, z, idx;
    tar(int a, int b, int c, int d, int zz, int id) :x1(a), x2(b), y1(c), y2(d) ,z(zz), idx(id) {}
    tar() {}
    bool operator < (const tar &b) {
        return z < b.z;
    }
};
tar tars[VS]; int m;

int hit[VS];

inline void reportSin(kd *root) {
    printf("(");
    for(int i=0;i<DIM;i++)
        if(i!=DIM-1) printf("%d,",ps1[root->vidx][i]);
        else printf("%d",ps1[root->vidx][i]);
    printf(")");
    printf(" key = %d min = %d\n", root->key, root->mins);
}

void dfs(kd *v, int depth) {
    if (!v) return;
    dfs(v->l, depth + 1);
    for (int i = 0; i < depth; i++) putchar(' ');
    reportSin(v);
    dfs(v->r, depth + 1);
}

void print(void *p) {
    dfs((kd *)p, 0);
}

int main() {
    memset(hit, 0, sizeof(hit) );
    scanf("%d", &m);
    for (int i = 0; i < m; i ++) {
        tars[i].idx = i;
        scanf("%d%d%d%d%d", &tars[i].x1, &tars[i].x2, &tars[i].y1, &tars[i].y2, &tars[i].z);
    }
    std::sort(tars, tars + m);
    int ans = 0;
    scanf("%d", &n); int tempn = 0;
    int a, b;
    for (int i = 0; i < n; i ++) {
        scanf("%d %d", &a, &b);
        auto ite = mm.find( {a, b} );
        if (ite == mm.end() ) {
            ps1[tempn][0] = a, ps1[tempn][1] = b, tempn ++;
            mm[ {a, b} ] = set<int> {i};
        } else ite->second.insert(i);
    }
    //for (int i = 0;i < tempn; i ++) {
        //printf("%d %d\n", ps1[i][0], ps1[i][1]);
    //}
    iniOd(tempn);
    root=buildKd(0,tempn-1,0);
    for (int i = 0; i < tempn; i ++) {
        auto ite = mm.find( {ps1[i][0], ps1[i][1]} );
        for (int a: ite->second) ns[a] = nn[i];
    }
    //print(root);
    int pp1[DIM],pp2[DIM];
    int p1[DIM][DIM],p2[DIM][DIM];
    iniSearch();
    preprocess(root,0);
    for (int i = 0; i < m; i ++) {
        pp1[0] = tars[i].x1, pp1[1] = tars[i].y1;
        pp2[0] = tars[i].x2, pp2[1] = tars[i].y2;
        convSearRange(p1, p2, pp1, pp2);
        int vidx = query(root, p1, p2);
        //if (vidx != INT_MAX) {
            //int ii = ns[vidx] -> vidx;
            //printf("(%d,%d)-(%d,%d) who = %d, %d vidx = %d\n", tars[i].x1, tars[i].y1, tars[i].x2, tars[i].y2, ps1[ii][0], ps1[ii][1], vidx);
        //}
        if (vidx != INT_MAX) {
            ans ++;
            hit[vidx + 1] = tars[i].idx + 1;
            int ii = ns[vidx] -> vidx;
            auto &ss = mm[ {ps1[ii][0], ps1[ii][1]} ];
            ss.erase(ss.begin());
            if (ss.size() == 0)
                update(root, ii , INT_MAX);
            else update(root, ii, *ss.begin() );
        }
    }
    for (int i = 1; i <= n; i ++) {
        printf("%d\n", hit[i]);
    }

    return 0;

}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string.h>
#include <limits.h>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

using namespace std;

const int VS=1e5+20,DIM=2;
int n;
int ps1[VS][DIM];
int ps[VS][DIM][DIM];
int od[DIM][VS],temp[VS];

struct kd {
    int vidx, key, mins;
    kd *l,*r,*p;
    kd(int k=0):vidx(k), key(k) { l=r=p=0; }
    void maintain() {
        mins = key;
        if (l) {
            mins = std::min(mins, l->mins);
        }
        if (r) {
            mins = std::min(mins, r->mins);
        }
    }
};

kd * root;
kd *nn[VS];

inline int cmp (int * a,int *b) {
    for(int i=0;i<DIM;i++) {
        if(a[i]<b[i]) return -1;
        if(a[i]>b[i]) return 1;
    }
    return 0;
}

inline void assign(int *a,int *b) {
    for(int i=0;i<DIM;i++) a[i]=b[i];
}

inline int * min(int *a,int *b) {
    if(cmp(a,b)<0) return a;
    else return b;
}

inline int * max(int *a,int *b) {
    if(cmp(a,b)>0) return a;
    else return b;
}

inline void CoorConvert(int (*ps)[DIM],int *ps1) {
    for(int d=0;d<DIM;d++) {
        for(int idx=0;idx<DIM;idx++) {
            if(idx==d) ps[d][idx]=ps1[0];
            else if(idx==0) ps[d][idx]=ps1[d];
            else ps[d][idx]=ps1[idx];
        }
    }
}

void iniOd() {
    for(int i=0;i<n;i++) CoorConvert(ps[i],ps1[i]);
    for(int i=0;i<DIM;i++) for(int v=1;v<=n;v++) od[i][v]=v;
    for(int i=0;i<DIM;i++)
        std::sort(od[i],od[i]+n,[i](int a,int b) {
            return cmp(ps[a][i],ps[b][i])<0;
        });
}

kd* buildKd(int i,int j,int dep) {
    if(i>j) return 0;
    int dim=dep%DIM,mid=(i+j)>>1,tt=od[dim][mid],x,y;
    if(i!=j)
        for(int d=0;d<=DIM-1;d++) {
            if(d!=dim) {
                x=i,y=mid+1;
                for(int ele=i;ele<=j;ele++) {
                    int cur=od[d][ele];
                    if(cur!=tt) {
                        if(cmp(ps[cur][dim],ps[tt][dim])<=0) temp[x++]=cur;
                        else temp[y++]=cur;
                    }
                }
                temp[mid]=tt;
                for(int ele=i;ele<=j;ele++) od[d][ele]=temp[ele];
            }
        }
    kd *l=buildKd(i,mid-1,dep+1);
    kd *r=buildKd(mid+1,j,dep+1);
    kd *ret=new kd(tt); ret->l=l,ret->r=r;
    nn[tt] = ret; ret->maintain();
    if(l) l->p=ret; if(r) r->p=ret;
    return ret;
}

int low[VS][DIM][DIM],up[VS][DIM][DIM];

void preprocess(kd *root,int dep) {
    if(!root) return ;
    int dim=dep%DIM;
    if(root->l) {
        int lvidx=root->l->vidx;
        for(int i=0;i<DIM;i++)
            assign(low[lvidx][i],low[root->vidx][i]),assign(up[lvidx][i],up[root->vidx][i]);
        assign(up[lvidx][dim],ps[root->vidx][dim]);
        preprocess(root->l,dep+1);
    }
    if(root->r) {
        int rvidx=root->r->vidx;
        for(int i=0;i<DIM;i++)
            assign(low[rvidx][i],low[root->vidx][i]),assign(up[rvidx][i],up[root->vidx][i]);
        assign(low[rvidx][dim],ps[root->vidx][dim]);
        preprocess(root->r,dep+1);
    }
}

inline int interType(kd *root,int (*p1)[DIM],int (*p2)[DIM]) {
    bool conta=1; bool seper=0; int vidx=root->vidx;
    for(int i=0;i<DIM;i++) {
        if(!(cmp(low[vidx][i],p1[i])>=0&&cmp(up[vidx][i],p2[i])<=0)) conta=0;
        if(cmp(max(low[vidx][i],p1[i]),min(up[vidx][i],p2[i]))>=0) seper=1;
    }
    if(conta) return 1;
    if(seper) return 3;
    return 2;
}

inline bool lieIn(kd *root,int (*p1)[DIM],int (*p2)[DIM]) {
    for(int i=0;i<DIM;i++) {
        if(cmp(ps[root->vidx][i],p1[i])<0||cmp(ps[root->vidx][i],p2[i])>0) return 0;
    }
    return 1;
}

void iniSearch() {
	if(root) {
        for(int d=0;d<DIM;d++) {
            for(int idx=0;idx<DIM;idx++) {
                low[root->vidx][d][idx]=INT_MIN;
                up[root->vidx][d][idx]=INT_MAX;
            }
        }
    }
}

void convSearRange(int (*p1)[DIM],int (*p2)[DIM],int *pp1,int *pp2) {
    for(int d=0;d<DIM;d++) {
        p1[d][0]=pp1[d],p2[d][0]=pp2[d];
        for(int idx=1;idx<DIM;idx++) {
            p1[d][idx]=INT_MIN,p2[d][idx]=INT_MAX;
        }
    }
}

int query(kd *root,int (*p1)[DIM],int (*p2)[DIM]) {
    if(!root) return INT_MAX;
    int res = INT_MAX;
    if(lieIn(root,p1,p2)) res = std::min(res, root->key);
    if(root->l) {
        int type=interType(root->l,p1,p2);
        if(type==1) res = std::min(res, root->l->mins);
        else if(type==2) res = std::min(res, query(root->l,p1,p2) );
    }
    if(root->r) {
        int type=interType(root->r,p1,p2);
        if(type==1) res = std::min(res, root->r->mins);
        else if(type==2) res = std::min(res, query(root->r,p1,p2) );
    }
    return res;
}

void update(kd *root, int vidx, int val) {
    kd *kk = nn[vidx];
    kk->key = val;
    while (kk) {
        kk->maintain();
        kk = kk->p;
    }
}

struct tar{
    int x1, x2, y1, y2, z;
    tar(int a, int b, int c, int d, int zz) :x1(a), x2(b), y1(c), y2(d) ,z(zz) {}
    tar() {}
    bool operator < (const tar &b) {
        return z < b.z;
    }
};
tar tars[VS]; int m;

int hit[VS];

int main() {
    memset(hit, 0, sizeof(hit) );
    scanf("%d", &m);
    for (int i = 0; i < m; i ++) {
        scanf("%d%d%d%d%d", &tars[i].x1, &tars[i].x2, &tars[i].y1, &tars[i].y2, &tars[i].z);
    }
    std::sort(tars, tars + m);
    int ans = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i ++) {
        scanf("%d%d", &ps1[i][0], &ps1[i][1]);
    }
    iniOd();
    root=buildKd(0,n-1,0);
    int pp1[DIM],pp2[DIM];
    int p1[DIM][DIM],p2[DIM][DIM];
    iniSearch();
    preprocess(root,0);
    for (int i = 0; i < m; i ++) {
        pp1[0] = tars[i].x1, pp1[1] = tars[i].y1;
        pp2[0] = tars[i].x2, pp2[1] = tars[i].y2;
        convSearRange(p1, p2, pp1, pp2);
        int vidx = query(root, p1, p2);
        if (vidx != INT_MAX) {
            ans ++;
            hit[vidx + 1] = i + 1;
            update(root, vidx , INT_MAX);
        }
    }
    for (int i = 1; i <= n; i ++) {
        printf("%d\n", hit[i]);
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string.h>
#include <limits.h>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

using namespace std;

const int VS=1e5+20,DIM=2;
int n;
int ps1[VS][DIM];
int ps[VS][DIM][DIM];
int od[DIM][VS],temp[VS];

struct kd {
    int vidx, key, mins;
    kd *l,*r,*p;
    kd(int k=0, int ke = 0):vidx(k), key(ke) { l=r=p=0; }
    void maintain() {
        mins = key;
        if (l) {
            mins = std::min(mins, l->mins);
        }
        if (r) {
            mins = std::min(mins, r->mins);
        }
    }
};

kd * root;
kd *nn[VS], *ns[VS];

inline int cmp (int * a,int *b) {
    for(int i=0;i<DIM;i++) {
        if(a[i]<b[i]) return -1;
        if(a[i]>b[i]) return 1;
    }
    return 0;
}

inline void assign(int *a,int *b) {
    for(int i=0;i<DIM;i++) a[i]=b[i];
}

inline int * min(int *a,int *b) {
    if(cmp(a,b)<0) return a;
    else return b;
}

inline int * max(int *a,int *b) {
    if(cmp(a,b)>0) return a;
    else return b;
}

inline void CoorConvert(int (*ps)[DIM],int *ps1) {
    for(int d=0;d<DIM;d++) {
        for(int idx=0;idx<DIM;idx++) {
            if(idx==d) ps[d][idx]=ps1[0];
            else if(idx==0) ps[d][idx]=ps1[d];
            else ps[d][idx]=ps1[idx];
        }
    }
}

void iniOd(int n) {
    for(int i=0;i<n;i++) CoorConvert(ps[i],ps1[i]);
    for(int i=0;i<DIM;i++) for(int v=1;v<=n;v++) od[i][v]=v;
    for(int i=0;i<DIM;i++)
        std::sort(od[i],od[i]+n,[i](int a,int b) {
            return cmp(ps[a][i],ps[b][i])<0;
        });
}

map<pair<int, int>, set<int> > mm;

kd* buildKd(int i,int j,int dep) {
    if(i>j) return 0;
    int dim=dep%DIM,mid=(i+j)>>1,tt=od[dim][mid],x,y;
    if(i!=j)
        for(int d=0;d<=DIM-1;d++) {
            if(d!=dim) {
                x=i,y=mid+1;
                for(int ele=i;ele<=j;ele++) {
                    int cur=od[d][ele];
                    if(cur!=tt) {
                        if(cmp(ps[cur][dim],ps[tt][dim])<=0) temp[x++]=cur;
                        else temp[y++]=cur;
                    }
                }
                temp[mid]=tt;
                for(int ele=i;ele<=j;ele++) od[d][ele]=temp[ele];
            }
        }
    kd *l=buildKd(i,mid-1,dep+1);
    kd *r=buildKd(mid+1,j,dep+1);
    kd *ret=new kd(tt, *(mm[ {ps1[tt][0], ps1[tt][1]} ].begin() ) ); ret->l=l,ret->r=r;
    nn[tt] = ret; ret->maintain();
    if(l) l->p=ret; if(r) r->p=ret;
    return ret;
}

int low[VS][DIM][DIM],up[VS][DIM][DIM];

void preprocess(kd *root,int dep) {
    if(!root) return ;
    int dim=dep%DIM;
    if(root->l) {
        int lvidx=root->l->vidx;
        for(int i=0;i<DIM;i++)
            assign(low[lvidx][i],low[root->vidx][i]),assign(up[lvidx][i],up[root->vidx][i]);
        assign(up[lvidx][dim],ps[root->vidx][dim]);
        preprocess(root->l,dep+1);
    }
    if(root->r) {
        int rvidx=root->r->vidx;
        for(int i=0;i<DIM;i++)
            assign(low[rvidx][i],low[root->vidx][i]),assign(up[rvidx][i],up[root->vidx][i]);
        assign(low[rvidx][dim],ps[root->vidx][dim]);
        preprocess(root->r,dep+1);
    }
}

inline int interType(kd *root,int (*p1)[DIM],int (*p2)[DIM]) {
    bool conta=1; bool seper=0; int vidx=root->vidx;
    for(int i=0;i<DIM;i++) {
        if(!(cmp(low[vidx][i],p1[i])>=0&&cmp(up[vidx][i],p2[i])<=0)) conta=0;
        if(cmp(max(low[vidx][i],p1[i]),min(up[vidx][i],p2[i]))>=0) seper=1;
    }
    if(conta) return 1;
    if(seper) return 3;
    return 2;
}

inline bool lieIn(kd *root,int (*p1)[DIM],int (*p2)[DIM]) {
    for(int i=0;i<DIM;i++) {
        if(cmp(ps[root->vidx][i],p1[i])<0||cmp(ps[root->vidx][i],p2[i])>0) return 0;
    }
    return 1;
}

void iniSearch() {
	if(root) {
        for(int d=0;d<DIM;d++) {
            for(int idx=0;idx<DIM;idx++) {
                low[root->vidx][d][idx]=INT_MIN;
                up[root->vidx][d][idx]=INT_MAX;
            }
        }
    }
}

void convSearRange(int (*p1)[DIM],int (*p2)[DIM],int *pp1,int *pp2) {
    for(int d=0;d<DIM;d++) {
        p1[d][0]=pp1[d],p2[d][0]=pp2[d];
        for(int idx=1;idx<DIM;idx++) {
            p1[d][idx]=INT_MIN,p2[d][idx]=INT_MAX;
        }
    }
}

int opt;

void query(kd *root,int (*p1)[DIM],int (*p2)[DIM]) {
    if(!root) return ;
    if (root -> mins == INT_MAX) return ;
    else if (root -> mins >= opt) return ;
    if(lieIn(root,p1,p2)) opt = std::min(opt, root->key);
    if(root->l) {
        int type=interType(root->l,p1,p2);
        if(type==1) opt = std::min(opt, root->l->mins);
        else if(type==2) query(root->l,p1,p2);
    }
    if(root->r) {
        int type=interType(root->r,p1,p2);
        if(type==1) opt = std::min(opt, root->r->mins);
        else if(type==2) query(root->r,p1,p2);
    }
}

void update(kd *root, int vidx, int val) {
    kd *kk = nn[vidx];
    kk->key = val;
    while (kk) {
        kk->maintain();
        kk = kk->p;
    }
}

struct tar{
    int x1, x2, y1, y2, z, idx;
    tar(int a, int b, int c, int d, int zz, int id) :x1(a), x2(b), y1(c), y2(d) ,z(zz), idx(id) {}
    tar() {}
    bool operator < (const tar &b) {
        return z < b.z;
    }
};
tar tars[VS]; int m;

int hit[VS];

inline void reportSin(kd *root) {
    printf("(");
    for(int i=0;i<DIM;i++)
        if(i!=DIM-1) printf("%d,",ps1[root->vidx][i]);
        else printf("%d",ps1[root->vidx][i]);
    printf(")");
    printf(" key = %d min = %d\n", root->key, root->mins);
}

void dfs(kd *v, int depth) {
    if (!v) return;
    dfs(v->l, depth + 1);
    for (int i = 0; i < depth; i++) putchar(' ');
    reportSin(v);
    dfs(v->r, depth + 1);
}

void print(void *p) {
    dfs((kd *)p, 0);
}

int main() {
    memset(hit, 0, sizeof(hit) );
    scanf("%d", &m);
    for (int i = 0; i < m; i ++) {
        tars[i].idx = i;
        scanf("%d%d%d%d%d", &tars[i].x1, &tars[i].x2, &tars[i].y1, &tars[i].y2, &tars[i].z);
    }
    std::sort(tars, tars + m);
    int ans = 0;
    scanf("%d", &n); int tempn = 0;
    int a, b;
    for (int i = 0; i < n; i ++) {
        scanf("%d %d", &a, &b);
        auto ite = mm.find( {a, b} );
        if (ite == mm.end() ) {
            ps1[tempn][0] = a, ps1[tempn][1] = b, tempn ++;
            mm[ {a, b} ] = set<int> {i};
        } else ite->second.insert(i);
    }
    //for (int i = 0;i < tempn; i ++) {
        //printf("%d %d\n", ps1[i][0], ps1[i][1]);
    //}
    iniOd(tempn);
    root=buildKd(0,tempn-1,0);
    for (int i = 0; i < tempn; i ++) {
        auto ite = mm.find( {ps1[i][0], ps1[i][1]} );
        for (int a: ite->second) ns[a] = nn[i];
    }
    //print(root);
    int pp1[DIM],pp2[DIM];
    int p1[DIM][DIM],p2[DIM][DIM];
    iniSearch();
    preprocess(root,0);
    for (int i = 0; i < m; i ++) {
        pp1[0] = tars[i].x1, pp1[1] = tars[i].y1;
        pp2[0] = tars[i].x2, pp2[1] = tars[i].y2;
        convSearRange(p1, p2, pp1, pp2);
        opt = INT_MAX;
        query(root, p1, p2);
        //if (vidx != INT_MAX) {
            //int ii = ns[vidx] -> vidx;
            //printf("(%d,%d)-(%d,%d) who = %d, %d vidx = %d\n", tars[i].x1, tars[i].y1, tars[i].x2, tars[i].y2, ps1[ii][0], ps1[ii][1], vidx);
        //}
        if (opt != INT_MAX) {
            ans ++;
            hit[opt + 1] = tars[i].idx + 1;
            int ii = ns[opt] -> vidx;
            auto &ss = mm[ {ps1[ii][0], ps1[ii][1]} ];
            ss.erase(ss.begin());
            if (ss.size() == 0)
                update(root, ii , INT_MAX);
            else update(root, ii, *ss.begin() );
        }
    }
    for (int i = 1; i <= n; i ++) {
        printf("%d\n", hit[i]);
    }

    return 0;

}


 #include<cstdio>
#include<algorithm>
using namespace std;
struct point{
  int x1,x2,y1,y2,id,z;
};
int n,m;
int pre[100050],suc[100050];
point a[100050];
bool cmp(point x,point y){
  return x.z<y.z?true:false;
}
int main(){
  scanf("%d",&n);
  for (int i=1;i<=n;i++){
    scanf("%d%d%d%d%d",&a[i].x1,&a[i].x2,&a[i].y1,&a[i].y2,&a[i].z);
    a[i].id=i;
  }
  sort(a+1,a+1+n,cmp);
  for (int i=1;i<=n;i++){
    pre[i]=i-1;suc[i]=i+1;
  }
  scanf("%d",&m);
  int x,y,first=1,j;
  for (;m--;){
    scanf("%d%d",&x,&y);
	for (j=first;j<=n;j=suc[j]){
	  if (x>=a[j].x1 && x<=a[j].x2 && y<=a[j].y2 && y>=a[j].y1) break;
	}
	if (j>n){
	  printf("0\n");
	  continue;
	}
	printf("%d\n",a[j].id);
	if (j==first){
	  first=suc[j];
	  continue;
	}
	pre[suc[j]]=pre[j];
	suc[pre[j]]=suc[j];
  }
  return 0;
}


#include <bits/stdc++.h>
#define uint unsigned long long
#define ll long long
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define ept 1e-9

using namespace std;
inline int read()
{
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}
inline ll read1()
{
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}

const int N = 100005;
struct Node
{
	int x1, x2, y1, y2, z, p;
}a[N];
int n, m, pre[N],nxt[N];

inline bool cmp(const Node &x,const Node &y)
{
	return x.z < y.z;
}
int main()
{
	n = read();
	rep(i, 1, n)
	{
		a[i].x1 = read();
		a[i].x2 = read();
		a[i].y1 = read();
		a[i].y2 = read();
		a[i].z = read();
		a[i].p = i;
	}
	sort(a + 1, a + n + 1, cmp);
	rep(i, 1, n) pre[i] = i - 1, nxt[i] = i + 1;
	nxt[0] = 1;
	pre[0] = n;
	nxt[n] = 0;
	m = read();
	rep(i, 1, m)
	{
		int x = read();
		int y = read();
		int j = 0;
		for(j = nxt[0]; j; j = nxt[j])
			if(x >= a[j].x1 && x <= a[j].x2 && y >= a[j].y1 && y <= a[j].y2)
			{
				nxt[pre[j]] = nxt[j];
				pre[nxt[j]] = pre[j];
				break;
			}
		printf("%d\n", a[j].p);
	}
	return 0;
}


#include <bits/stdc++.h>
#define uint unsigned long long
#define ll long long
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define ept 1e-9
#define INF 0x3f3f3f3f
using namespace std;
inline int read()
{
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}
inline ll read1()
{
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int N = 1e5 + 10;
struct P
{
	int x, y;
} p[N];
struct Rec
{
	int x1, y1, x2, y2, z;
	Rec(){}
	Rec( P q ):x1(q.x),y1(q.y),x2(q.x),y2(q.y){}
	inline bool cover( const Rec &r ) const
	{
		return x1 <= r.x1 && r.x2 <= x2 && y1 <= r.y1 && r.y2 <= y2;
	}
	inline bool jiao( const Rec &r ) const
	{
		return !(x2 < r.x1 || x1 > r.x2) && !(y2 < r.y1 || y1 > r.y2);
	}
} R[N];
inline bool cpx(int a, int b)
{
	return p[a].x != p[b].x ? p[a].x < p[b].x : p[a].y < p[b].y;
}
inline bool cpy(int a, int b)
{
	return p[a].y != p[b].y ? p[a].y < p[b].y : p[a].x < p[b].x;
}
inline bool cpz(int a, int b)
{
	return R[a].z < R[b].z;
}

struct KD_T
{
	Rec val[8 * N];
	bool flag[8 * N];
	void pull(int rt)
	{
		val[rt].x1 = min(val[ls].x1, val[rs].x1);
		val[rt].y1 = min(val[ls].y1, val[rs].y1);
		val[rt].x2 = max(val[ls].x2, val[rs].x2);
		val[rt].y2 = max(val[ls].y2, val[rs].y2);
		val[rt].z = min(val[ls].z, val[rs].z);
	}
	void init(int rt, int n, int *lst, int lv)
	{
		if (n == 1)
		{
			val[rt] = p[lst[0]];
			val[rt].z = lst[0];
			flag[rt] = 1;
			return;
		}
		sort(lst, lst + n, lv % 2 == 0 ? cpx : cpy);
		init(ls, n / 2, lst, lv + 1);
		init(rs, n - n / 2, lst + n / 2, lv + 1);
		pull(rt);
	}
	void del_min( int rt )
	{
		if (flag[rt])
		{
			val[rt].z = INF;
			return;
		}
		if (val[ls].z == val[rt].z) del_min(rt * 2);
		else del_min(rt * 2 + 1);
		pull(rt);
	}
	void up( int rt )
	{
		do pull(rt);
		while (rt /= 2);
	}
	pii Q(int rt, const Rec &r)
	{
		if (!r.jiao(val[rt])) return mp(INF, -1);
		if (r.cover(val[rt])) return mp(val[rt].z, rt);
		return min(Q(rt * 2, r), Q(rt * 2 + 1, r));
	}
} kdt;

int n,m;
int ans[N],lst[N],srt[N];

int main()
{
	n = read();
	rep(i, 0, n - 1)
	{
	    R[i].x1 = read();
	    R[i].x2 = read();
	    R[i].y1 = read();
	    R[i].y2 = read();
	    R[i].z = read();
	}
	m = read();
	rep(i, 0, m - 1) p[i].x = read(), p[i].y = read();
	rep(i, 0, m - 1) lst[i] = i;
	kdt.init(1, m, lst, 0);
	rep(i, 0, n - 1) srt[i] = i;
	sort(srt, srt + n, cpz);
	rep(i, 0, n - 1)
	{
		pii ret = kdt.Q(1, R[srt[i]]);
		if (ret.X == INF) continue;
		kdt.del_min(ret.Y);
		kdt.up(ret.Y / 2);
		ans[ret.X] = srt[i] + 1;
	}
	rep(i, 0, m - 1) printf("%d\n", ans[i]);
}


// nlather (Nishant Raj Lather)
// Chrollo_Lucifer

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1e9+7
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define rep(i, x, n) for(ll i = x; i < n; i++)
#define rrep(i, x, n) for(ll i = x; i >= n; i--)
#define all(v) v.begin(),v.end()
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define e emplace
#define mp make_pair
double PI=3.14159265358979323846;
typedef long long int ll;
typedef long double ld;
typedef pair< ll, ll > pii;
typedef vector< ll > vi;
typedef vector< vi > vvi;

map< pii, ll > ind;

bool cum(pii p1, pii p2) {
	return (p1.ss - p1.ff) * (p2.ff - p1.ss) < 0;
}

int main()
{
	boost
	ll n, x, y;
	cin >> n;
	vector< pii > a, b;
	rep(i, 0, n) {
		cin >> x >> y;
		if(x > y) a.eb(x, y);
		else b.eb(x, y);
		ind[{x, y}] = i + 1;
	}
	vector< pii > &v = (a.size() > b.size()) ? a : b;
	sort(all(v), cum);
	cout << v.size() << endl;
	for(pii &p : v) cout << ind[p] << " ";
	cout << endl;
}


// nlather (Nishant Raj Lather)
// Chrollo_Lucifer

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1e9+7
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define rep(i, x, n) for(ll i = x; i < n; i++)
#define rrep(i, x, n) for(ll i = x; i >= n; i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define e emplace
#define mp make_pair
double PI=3.14159265358979323846;
typedef long long int ll;
typedef long double ld;
typedef pair< ll, ll > pii;
typedef vector< ll > vi;
typedef vector< vi > vvi;

map< pii, ll > ind;
vector< pii > a, b;

int main()
{
	boost
	ll n, x, y;
	cin >> n;
	rep(i, 0, n) {
		cin >> x >> y;
		if(x > y) a.eb(x, y);
		else b.eb(x, y);
		ind[{x, y}] = i + 1;
	}
	if(a.size() > b.size()) {
		cout << a.size() << endl;
		sort(all(a));
		for(pii p : a) cout << ind[p] << " ";
		cout << endl;
	} else {
		cout << b.size() << endl;
		sort(rall(b));
		for(pii p : b) cout << ind[p] << " ";
		cout << endl;
	}
}


// nlather (Nishant Raj Lather)
// Chrollo_Lucifer

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1e9+7
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define rep(i, x, n) for(ll i = x; i < n; i++)
#define rrep(i, x, n) for(ll i = x; i >= n; i--)
#define all(v) v.begin(),v.end()
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define e emplace
#define mp make_pair
double PI=3.14159265358979323846;
typedef long long int ll;
typedef long double ld;
typedef pair< ll, ll > pii;
typedef vector< ll > vi;
typedef vector< vi > vvi;

map< pii, ll > ind;
vector< pii > a, b;
bool cum(pii p1, pii p2) {
	return (((p1.ss - p1.ff) * (p2.ff - p1.ss)) < 0LL);
}

int main()
{
	boost
	ll n, x, y;
	cin >> n;
	rep(i, 0, n) {
		cin >> x >> y;
		if(x > y) a.pb({x, y});
		else b.pb({x, y});
		ind[{x, y}] = i + 1;
	}
	vector< pii > v = (a.size() > b.size()) ? a : b;
	sort(all(v), cum);
	cout << v.size() << endl;
	for(pii p : v) cout << ind[p] << " ";
	cout << endl;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n;
	cin>>n;

	vector<pair<pair<int,int> ,int> >v1,v2;
	int a,b,i;

	for(i=0;i<n;i++)
	{
		cin>>a>>b;
		if(a>b)
		{
			v2.push_back({{a,b},i+1});
		}
		else
		{
			v1.push_back({{a,b},i+1});
		}
	}

	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());

	//for v1

	int j,st=0,maxx=0;

	for(i=0;i<v1.size();i++)
	{
		int count=1;
		for(j=i+1;j<v1.size();j++)
		{
			if(v1[j-1].first.second>v1[j].first.first)
			{
				count++;
			}
			else
			{
				break;
			}
		}
		if(maxx<count)
		{
			maxx=count;
			st=i;
		}
		i=j-1;
	}

	//for v2

	int st2=0,maxx2=0;

	for(i=0;i<v2.size();i++)
	{
		int count=1;
		for(j=i+1;j<v2.size();j++)
		{
			if(v2[j-1].first.second<v2[j].first.first)
			{
				count++;
			}
			else
			{
				break;
			}
		}
		if(maxx2<count)
		{
			maxx2=count;
			st2=i;
		}
		i=j-1;
	}

	if(maxx>maxx2)
	{
		cout<<maxx<<endl;
		while(maxx)
		{
			maxx--;
			cout<<v1[st].second<<" ";
			st++;
		}
		cout<<endl;
	}
	else
	{
		cout<<maxx2<<endl;
		while(maxx2)
		{
			maxx2--;
			cout<<v2[st2].second<<" ";
			st2++;
		}
		cout<<endl;
	}
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n;
	cin>>n;

	vector<pair<pair<int,int> ,int> >v1,v2;
	int a,b,i;

	for(i=0;i<n;i++)
	{
		cin>>a>>b;
		if(a>b)
		{
			v2.push_back({{a,b},i+1});
		}
		else
		{
			v1.push_back({{a,b},i+1});
		}
	}

	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());

	if(v1.size()>v2.size())
	{
		cout<<v1.size()<<endl;
		for(auto uj:v1)
			cout<<uj.second<<" ";
		cout<<endl;
	}
	else
	{
		cout<<v2.size()<<endl;
		for(auto uj:v2)
			cout<<uj.second<<" ";
		cout<<endl;
	}
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n;
	cin>>n;

	vector<pair<pair<int,int> ,int> >v1,v2;
	int a,b,i;

	for(i=0;i<n;i++)
	{
		cin>>a>>b;
		if(a>b)
		{
			v2.push_back({{a,b},i+1});
		}
		else
		{
			v1.push_back({{a,b},i+1});
		}
	}

	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());

	//for v1

	int j,st=0,maxx=0;

	for(i=0;i<v1.size();i++)
	{
		int count=1;
		for(j=i+1;j<v1.size();j++)
		{
			if(v1[j-1].first.second>v1[j].first.first)
			{
				count++;
			}
			else
			{
				break;
			}
		}
		if(maxx<count)
		{
			maxx=count;
			st=i;
		}
		i=j-1;
	}

	//for v2

	int st2=0,maxx2=0;

	for(i=0;i<v2.size();i++)
	{
		int count=1;
		for(j=i+1;j<v2.size();j++)
		{
			if(v2[j-1].first.second<v2[j].first.first)
			{
				count++;
			}
			else
			{
				break;
			}
			if(maxx2<count)
			{
				maxx2=count;
				st2=i;
			}
			i=j-1;
		}
	}

	if(maxx>maxx2)
	{
		cout<<maxx<<endl;
		while(maxx)
		{
			maxx--;
			cout<<v1[st].second<<" ";
			st++;
		}
		cout<<endl;
	}
	else
	{
		cout<<maxx2<<endl;
		while(maxx2)
		{
			maxx2--;
			cout<<v2[st2].second<<" ";
			st2++;
		}
		cout<<endl;
	}
}


#include<bits/stdc++.h>

using namespace std;

bool ujcmp1(pair<pair<int,int> ,int>a,pair<pair<int,int> ,int>b)
{
	return a.first.second>b.first.second;
}

bool ujcmp2(pair<pair<int,int> ,int>a,pair<pair<int,int> ,int>b)
{
	return a.first.second<b.first.second;
}

int main()
{
	int n;
	cin>>n;

	vector<pair<pair<int,int> ,int> >v1,v2;
	int a,b,i;

	for(i=0;i<n;i++)
	{
		cin>>a>>b;
		if(a>b)
		{
			v2.push_back({{a,b},i+1});
		}
		else
		{
			v1.push_back({{a,b},i+1});
		}
	}

	sort(v1.begin(),v1.end(),ujcmp1);
	sort(v2.begin(),v2.end(),ujcmp2);

	if(v1.size()>v2.size())
	{
		cout<<v1.size()<<endl;
		for(auto uj:v1)
			cout<<uj.second<<" ";
		cout<<endl;
	}
	else
	{
		cout<<v2.size()<<endl;
		for(auto uj:v2)
			cout<<uj.second<<" ";
		cout<<endl;
	}
}


#include <bits/stdc++.h>

using namespace std;
int main()
{
    int n,x=0,y=0,z;
    cin >>n;
    vector<int> a(n),b(n),c,d;
    vector<int>::iterator it;
    for(int i=0;i<n;i++)
    {
        cin >>a[i]>>b[i];
        if(a[i]>b[i]){x++;c.push_back(a[i]);}
        else {y++;d.push_back(b[i]);}
    }
    z=c.size();
    if(x>=y)
    {
        cout <<x<<endl;
        sort(c.begin(),c.end());
        for(int i=0;i<z;++i)
        {
            it=find(a.begin(),a.end(),c[i]);
            cout <<it-a.begin()+1<<' ';
        }
    }
    else
    {
        cout <<y<<endl;
        sort(d.begin(),d.end());
        for(int i=n-z-1;i>=0;--i)
        {
            it=find(b.begin(),b.end(),d[i]);
            cout <<it-b.begin()+1<<' ';
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
bool cmp(int a,int b)
{
    return (a>b);
}
int main()
{
    int n,x=0,y=0;
    cin >>n;
    vector<int> a(n),b(n),c,d;
    vector<int>::iterator it;
    for(int i=0;i<n;i++)
    {
        cin >>a[i]>>b[i];
        if(a[i]>b[i]){x++;c.push_back(a[i]);}
        else {y++;d.push_back(b[i]);}
    }
    if(x>=y)
    {
        cout <<x<<endl;
        sort(c.begin(),c.end());
        for(int i=0;i<c.size();i++)
        {
            it=find(a.begin(),a.end(),c[i]);
            cout <<it-a.begin()+1<<' ';
        }
    }
    else
    {
        cout <<y<<endl;
        sort(d.begin(),d.end(),cmp);
        for(int i=0;i<d.size();i++)
        {
            it=find(b.begin(),b.end(),d[i]);
            cout <<it-b.begin()+1<<' ';
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
bool cmp(int a,int b)
{
    return (a>b);
}
int main()
{
    int n,x=0,y=0;
    cin >>n;
    vector<int> a(n),b(n),c,d;
    vector<int>::iterator it;
    for(int i=0;i<n;i++)
    {
        cin >>a[i]>>b[i];
        if(a[i]>b[i]){x++;c.push_back(a[i]);}
        else {y++;d.push_back(b[i]);}
    }
    if(x>=y)
    {
        cout <<x<<endl;
        sort(c.begin(),c.end());
        for(int i=0;i<c.size();i++)
        {
            it=find(a.begin(),a.end(),c[i]);
            cout <<it-a.begin()+1<<' ';
        }
    }
    else
    {
        cout <<y<<endl;
        sort(d.begin(),d.end());
        for(int i=0;i<d.size();i++)
        {
            it=find(b.begin(),b.end(),d[i]);
            cout <<it-b.begin()+1<<' ';
        }
    }
    return 0;
}