#include <bits/stdc++.h>
using namespace std;
struct way {
  int x, y, z;
} e[500010];
int fa[500010], ff[500010], id[500010], ti, tot, n, m, Q, q[500010], cl[500010],
    v[500010], ans[500010];
vector<int> g[500010], h[500010];
bool cmp(int x, int y) { return e[x].z < e[y].z; }
int getff(int x) {
  if (cl[x] != ti) {
    cl[x] = ti;
    ff[x] = fa[x];
  }
  if (ff[x] != x) ff[x] = getff(ff[x]);
  return ff[x];
}
int getfa(int x) {
  if (fa[x] != x) fa[x] = getfa(fa[x]);
  return fa[x];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].z);
    id[i] = i;
  }
  sort(id + 1, id + 1 + m, cmp);
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    ans[i] = 1;
    int k;
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      int x;
      scanf("%d", &x);
      g[x].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) fa[i] = ff[i] = i;
  for (int i = 1; i <= m; i++) {
    int j = i + 1;
    while (j <= m && e[id[i]].z == e[id[j]].z) j++;
    tot = 0;
    for (int k = i; k < j; k++) {
      for (int r = 0; r < g[id[k]].size(); r++) {
        int x = g[id[k]][r];
        if (!v[x]) {
          v[x] = ++tot;
          q[tot] = x;
        }
        h[v[x]].push_back(id[k]);
      }
    }
    for (int k = 1; k <= tot; k++) {
      ti++;
      for (int r = 0; r < h[k].size(); r++) {
        int u = h[k][r];
        int x = getff(e[u].x), y = getff(e[u].y);
        if (x == y) {
          ans[q[k]] = 0;
          break;
        } else
          ff[x] = y;
      }
      h[k].clear();
      v[q[k]] = 0;
    }
    for (int k = i; k < j; k++) {
      int x = getfa(e[id[k]].x), y = getfa(e[id[k]].y);
      if (x != y) fa[x] = y;
    }
    i = j - 1;
  }
  for (int i = 1; i <= Q; i++)
    if (ans[i])
      puts("YES");
    else
      puts("NO");
}
