#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
inline int min(int a, int b) { return a < b ? a : b; }
inline int max(int a, int b) { return a > b ? a : b; }
struct Node {
  int x, y, t, id, aid;
} bus[200010];
int busy[200010];
struct node {
  int l, r, v;
  int mid() { return (l + r) >> 1; }
} tree[200010 * 4];
int n, m, tot;
void create(int l, int r, int id) {
  tree[id].l = l;
  tree[id].r = r;
  tree[id].v = 0;
  if (l == r) return;
  int mid = tree[id].mid();
  create(l, mid, id << 1);
  create(mid + 1, r, (id << 1) | 1);
}
void update(int l, int id, int val) {
  if (tree[id].l == tree[id].r) {
    if (tree[id].v < val) tree[id].v = val;
    return;
  }
  int mid = tree[id].mid();
  if (l <= mid)
    update(l, id << 1, val);
  else
    update(l, (id << 1) | 1, val);
  tree[id].v = max(tree[id << 1].v, tree[(id << 1) | 1].v);
}
int an;
void query(int l, int r, int id, int t) {
  if (tree[id].v < t) return;
  if (tree[id].l == tree[id].r) {
    an = min(tree[id].l, an);
    return;
  }
  int mid = tree[id].mid();
  if (r <= mid)
    query(l, r, id << 1, t);
  else if (l > mid)
    query(l, r, (id << 1) | 1, t);
  else {
    query(l, mid, id << 1, t);
    if (an == 0x7fffffff) query(mid + 1, r, (id << 1) | 1, t);
  }
}
int bin(int key) {
  int l = 1, r = tot, mid;
  while (l < r) {
    mid = (l + r) >> 1;
    if (busy[mid] == key)
      return mid;
    else if (busy[mid] < key)
      l = mid + 1;
    else
      r = mid;
  }
}
int cmp(Node a, Node b) {
  if (a.x != b.x) return a.x < b.x;
  return a.id < b.id;
}
int ans[200010];
int main() {
  int i, j, cnt;
  while (scanf("%d%d", &n, &m) != EOF) {
    mp.clear();
    for (i = 1; i <= n; i++)
      scanf("%d%d%d", &bus[i].x, &bus[i].y, &bus[i].t),
          busy[i] = bus[i].t, bus[i].id = 1, mp[bus[i].t] = i;
    for (i = 1; i <= m; i++)
      scanf("%d%d%d", &bus[i + n].x, &bus[i + n].y, &bus[i + n].t),
          busy[i + n] = bus[i + n].t, bus[i + n].id = 2, bus[i + n].aid = i;
    sort(busy + 1, busy + n + m + 1);
    tot = 2;
    for (i = 2; i <= n + m; i++) {
      if (busy[i] != busy[i - 1]) busy[tot++] = busy[i];
    }
    sort(bus + 1, bus + n + m + 1, cmp);
    create(1, 200000, 1);
    for (i = 1; i <= n + m; i++) {
      if (bus[i].id == 1) {
        update(bin(bus[i].t), 1, bus[i].y);
      } else {
        an = 0x7fffffff;
        query(bin(bus[i].t), 200000, 1, bus[i].y);
        if (an == 0x7fffffff)
          ans[bus[i].aid] = -1;
        else
          ans[bus[i].aid] = mp[busy[an]];
      }
    }
    for (i = 1; i <= m; i++) {
      if (i < m)
        printf("%d ", ans[i]);
      else
        printf("%d\n", ans[i]);
    }
  }
  return 0;
}
