#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9, maxn = 5e5 + 5;
int n, m;
struct edges {
  int x, y, v;
  bool operator<(const edges b) const { return v < b.v; }
} ed[maxn << 1];
struct query {
  int id, x, y, z;
  bool operator<(const query b) const {
    if (z == b.z) return id < b.id;
    return z < b.z;
  }
} qu[maxn];
int q, cnt = 0;
int tp = 0, sz[maxn], fa[maxn];
int op[maxn], ans[maxn];
int find(int x) { return fa[x] == x ? fa[x] : find(fa[x]); }
void merge(int x, int y) {
  if (x == y) return;
  if (sz[x] > sz[y]) swap(x, y);
  op[++tp] = x;
  fa[x] = y;
  sz[y] += sz[x];
}
void split() {
  int curtp = op[tp];
  sz[fa[curtp]] -= sz[curtp];
  fa[curtp] = curtp;
  --tp;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) sz[i] = 1, fa[i] = i;
  for (int i = 1; i <= m; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    ed[i] = (edges){x, y, z};
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int k;
    scanf("%d", &k);
    ans[i] = 1;
    for (int j = 1; j <= k; j++) {
      int x;
      scanf("%d", &x);
      qu[++cnt] = (query){i, ed[x].x, ed[x].y, ed[x].v};
    }
  }
  sort(ed + 1, ed + m + 1);
  sort(qu + 1, qu + cnt + 1);
  int stp = 1;
  for (int i = 1; i <= cnt;) {
    while (ed[stp].v < qu[i].z) merge(find(ed[stp].x), find(ed[stp].y)), ++stp;
    tp = 0;
    do {
      int fx = find(qu[i].x), fy = find(qu[i].y);
      if (fx == fy) ans[qu[i].id] = 0;
      merge(fx, fy);
      ++i;
    } while (qu[i].z == qu[i - 1].z && qu[i].id == qu[i - 1].id);
    while (tp) split();
  }
  for (int i = 1; i <= q; i++)
    if (ans[i])
      puts("YES");
    else
      puts("NO");
  return 0;
}
