#include <bits/stdc++.h>
using namespace std;
int N, M;
int Kal[200010];
int Var[200010];
int Har[200010];
int Pos[200010];
int Kd[200010 * 3];
int Res[200010];
pair<int, int> Sok[200010], Sov[200010];
int update(int k, int a, int b, int a1, int t) {
  if (a > a1 || b < a1) return Kd[k];
  if (a >= a1 && b <= a1) return Kd[k] = t;
  int ta = update(k * 2, a, (a + b) / 2, a1, t);
  int tb = update(k * 2 + 1, (a + b) / 2 + 1, b, a1, t);
  if (Var[ta] > Var[tb]) return Kd[k] = ta;
  return Kd[k] = tb;
}
int find(int k, int a, int b, int a1, int b1) {
  if (a > b1 || b < a1) return 0;
  if (a >= a1 && b <= b1) return Kd[k];
  int ta = find(k * 2, a, (a + b) / 2, a1, b1);
  int tb = find(k * 2 + 1, (a + b) / 2 + 1, b, a1, b1);
  if (Var[ta] > Var[tb]) return ta;
  return tb;
}
int comp(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first == b.first) return a.second > b.second;
  return a.first < b.first;
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N + M; i++) {
    scanf("%d%d%d", Kal + i, Var + i, Har + i);
    Sov[i] = pair<int, int>(Har[i], i);
    Sok[i] = pair<int, int>(Kal[i], i);
  }
  sort(Sok + 1, Sok + N + M + 1);
  sort(Sov + 1, Sov + N + M + 1, comp);
  Var[0] = -1;
  for (int i = 1; i <= N + M + 1; i++) Pos[Sov[i].second] = i;
  for (int i = 1, tmp; i <= N + M + 1; i++) {
    if (Sok[i].second <= N)
      update(1, 1, N + M, Pos[Sok[i].second], Sok[i].second);
    else {
      int lo, hi = N + M, mi;
      lo = Pos[Sok[i].second];
      while (lo < hi) {
        mi = (lo + hi) / 2;
        if (Var[find(1, 1, N + M, lo, mi)] >= Var[Sok[i].second])
          hi = mi;
        else
          lo = mi + 1;
      }
      tmp = find(1, 1, N + M, lo, hi);
      if (!tmp || Var[tmp] < Var[Sok[i].second])
        Res[Sok[i].second - N] = -1;
      else
        Res[Sok[i].second - N] = tmp;
    }
  }
  for (int i = 1; i <= M; i++) printf("%d ", Res[i]);
  printf("\n");
  return 0;
}
