#include <bits/stdc++.h>
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;
}
const int MAXN = 500010;
int n, m, maxx, Q, cnt;
int f[MAXN], flag[MAXN], ans[MAXN], sz[MAXN], pos[MAXN];
struct wy {
  int x, y, z, id;
} t[MAXN];
struct data {
  int x, y, id;
  int fa, son;
};
vector<data> g[MAXN];
inline int cmp(wy a, wy b) { return a.z < b.z; }
inline int getfather(int x) {
  if (f[x] == x) return x;
  return getfather(f[x]);
}
inline void cut(int x, int y) {
  sz[x] -= sz[y];
  f[y] = y;
  return;
}
int main() {
  n = read();
  m = read();
  cnt = 1;
  for (int i = 1; i <= m; ++i) {
    int x, y, z;
    x = read();
    y = read();
    z = read();
    t[i] = (wy){x, y, z, i};
    maxx = ((maxx) > (z) ? (maxx) : (z));
  }
  sort(t + 1, t + 1 + m, cmp);
  for (int i = 1; i <= m; ++i) pos[t[i].id] = i;
  for (int i = 1; i <= n; ++i) f[i] = i, sz[i] = 1;
  Q = read();
  for (int i = 1; i <= Q; ++i) {
    int k, x;
    k = read();
    for (int j = 1; j <= k; ++j) {
      x = read();
      g[t[pos[x]].z].push_back((data){t[pos[x]].x, t[pos[x]].y, i});
    }
  }
  for (int i = 1; i <= maxx; ++i) {
    int last = -1;
    if (g[i].size()) {
      int ww = (int)g[i].size();
      for (int j = 0; j < ww; ++j) {
        if (ans[g[i][j].id]) continue;
        data w = g[i][j];
        if (last == -1) last = j;
        int xx = getfather(w.x);
        int yy = getfather(w.y);
        if (xx == yy) {
          ans[w.id] = 1;
          int p = j - 1;
          while (p >= last) {
            cut(g[i][p].fa, g[i][p].son);
            --p;
          }
          last = -1;
          continue;
        } else {
          if (sz[xx] > sz[yy]) swap(xx, yy);
          g[i][j].fa = yy;
          g[i][j].son = xx;
          sz[yy] += sz[xx];
          f[xx] = yy;
        }
        if (j + 1 > ww || g[i][j + 1].id != w.id) {
          int p = j;
          while (p >= last) {
            cut(g[i][p].fa, g[i][p].son);
            --p;
          }
          last = -1;
        }
      }
    }
    while (cnt <= m && t[cnt].z == i) {
      int xx = getfather(t[cnt].x);
      int yy = getfather(t[cnt].y);
      if (xx == yy) {
        ++cnt;
        continue;
      }
      if (sz[xx] > sz[yy]) swap(xx, yy);
      f[xx] = yy;
      sz[yy] += sz[xx];
      ++cnt;
    }
  }
  for (int i = 1; i <= Q; ++i) puts(ans[i] ? "NO" : "YES");
  return 0;
}
