#include <bits/stdc++.h>
using namespace std;
struct bus {
  int first, second, t, id;
  bool operator<(const bus& a) const {
    return second != a.second ? second > a.second : id < a.id;
  }
} bs[100005 * 2];
set<int> b[100005 * 2];
map<int, int> tr;
int nn, ans[100005], xs[100005 * 2], ys[100005 * 2], xlen, ylen;
void init(int n) {
  nn = n;
  for (int first = 1; first <= nn; first++)
    b[first].clear(), b[first].insert(1000000013);
}
void add(int first, int d) {
  for (; first <= nn; first += first & -first) b[first].insert(d);
}
int get(int first, int t) {
  int res = 1000000013;
  for (; first > 0; first -= first & -first)
    res = min(res, *b[first].lower_bound(t));
  return res;
}
int main() {
  int n, m, i;
  while (~scanf("%d%d", &n, &m)) {
    int bslen = n + m;
    for (i = 0; i < bslen; i++) {
      scanf("%d%d%d", &bs[i].first, &bs[i].second, &bs[i].t);
      bs[i].id = i;
    }
    int xlen = 0, ylen = 0;
    for (i = 0; i < bslen; i++)
      xs[xlen++] = bs[i].first, ys[ylen++] = bs[i].second;
    sort(xs, xs + xlen);
    xlen = unique(xs, xs + xlen) - xs;
    sort(ys, ys + ylen);
    ylen = unique(ys, ys + ylen) - ys;
    for (i = 0; i < bslen; i++) {
      bs[i].first = lower_bound(xs, xs + xlen, bs[i].first) - xs + 1;
      bs[i].second = lower_bound(ys, ys + ylen, bs[i].second) - ys + 1;
    }
    tr.clear();
    tr[1000000013] = -1;
    for (i = 0; i < n; i++) tr[bs[i].t] = i + 1;
    sort(bs, bs + bslen);
    init(xlen);
    for (i = 0; i < bslen; i++)
      if (bs[i].id < n)
        add(bs[i].first, bs[i].t);
      else {
        int res = get(bs[i].first, bs[i].t);
        ans[bs[i].id - n] = tr[res];
      }
    for (i = 0; i < m; i++) printf("%d ", ans[i]);
    printf("\n");
  }
  return 0;
}
