#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  char zf = 1;
  char ch;
  while (ch != '-' && !isdigit(ch)) ch = getchar();
  if (ch == '-') zf = -1, ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * zf;
}
void write(long long y) {
  if (y < 0) putchar('-'), y = -y;
  if (y > 9) write(y / 10);
  putchar(y % 10 + '0');
}
inline void writeln(const long long y) {
  write(y);
  putchar('\n');
}
inline int min(const int x, const int y) { return x < y ? x : y; }
inline int max(const int x, const int y) { return x > y ? x : y; }
int i, j, k, m, n, x, y, z, cnt;
int la[1000010], fa[1000010], siz[1000010], top, g = 0;
int ask(int x) {
  while (fa[x] != x) x = fa[x];
  return x;
}
void merge(int x, int y) {
  if (x == y) return;
  if (siz[x] > siz[y]) swap(x, y);
  la[++top] = x;
  fa[x] = y;
  siz[y] += siz[x];
}
void undo() {
  int La = la[top];
  siz[fa[La]] -= siz[La];
  fa[La] = La;
  top--;
}
struct ed {
  int x, y, z;
  inline bool operator<(const ed s) const { return z < s.z; }
} q[1000010];
struct query {
  int id, x, y, val;
  inline bool operator<(const query s) const {
    if (val == s.val) return id < s.id;
    return val < s.val;
  }
} A[1000010];
int ans[1000010];
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) siz[i] = 1, fa[i] = i;
  for (int i = 1; i <= m; i++) {
    x = read();
    y = read();
    z = read();
    q[i] = {x, y, z};
  }
  k = read();
  for (int e = 1; e <= k; e++) {
    z = read();
    ans[e] = 1;
    for (int i = 1; i <= z; i++) {
      x = read();
      A[++cnt] = {e, q[x].x, q[x].y, q[x].z};
    }
  }
  sort(q + 1, q + m + 1);
  sort(A + 1, A + cnt + 1);
  int qd = 1;
  for (int i = 1; i <= cnt;) {
    while (q[qd].z < A[i].val) merge(ask(q[qd].x), ask(q[qd].y)), qd++;
    top = 0;
    do {
      if (ask(A[i].x) == ask(A[i].y)) ans[A[i].id] = 0;
      merge(ask(A[i].x), ask(A[i].y));
      i++;
    } while (A[i].val == A[i - 1].val && A[i].id == A[i - 1].id);
    while (top) undo();
  }
  for (int i = 1; i <= k; i++) puts(ans[i] ? "YES" : "NO");
  return 0;
}
