#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 50;
int ans[maxn], top = 0, fa[maxn], dep[maxn];
constexpr int BS = 1 << 25;
struct fastin {
  char buf[BS + 1], *inp = buf;
  fastin() { fread(buf, 1, BS, stdin); }
  template <typename T>
  fastin& operator>>(T& i) {
    i = 0;
    int f = 1;
    while (!isdigit(*inp))
      if (*inp++ == '-') f = -1;
    while (isdigit(*inp)) i = i * 10 + *inp++ - '0';
    i *= f;
    return *this;
  }
} fin;
struct Node {
  int x, y, dep;
} b[maxn];
struct node {
  int u, v, val;
  friend bool operator<(node a, node b) { return a.val < b.val; }
} edge[maxn * 2];
struct NODE {
  int u, v, val, id;
  friend bool operator<(NODE a, NODE b) {
    return a.val == b.val ? a.id < b.id : a.val < b.val;
  }
} qt[maxn];
int findfa(int x) { return fa[x] == x ? x : findfa(fa[x]); }
int uni(int x, int y) {
  int fax = findfa(x);
  int fay = findfa(y);
  if (fax == fay) return 1;
  if (dep[fax] > dep[fay]) swap(fax, fay);
  b[top++] = {fax, fay, dep[fay]};
  if (dep[fax] == dep[fay]) dep[fay]++;
  fa[fax] = fay;
  return 0;
}
void del(int k) {
  for (int i = 1; i <= k; i++) {
    Node tmp = b[--top];
    int x = tmp.x;
    int y = tmp.y;
    fa[x] = x;
    dep[y] = tmp.dep;
  }
}
int main() {
  int n, m;
  fin >> n >> m;
  for (int i = 1; i <= m; i++) {
    fin >> edge[i].u;
    fin >> edge[i].v;
    fin >> edge[i].val;
  }
  for (int i = 0; i <= n; i++) {
    fa[i] = i;
    dep[i] = 0;
  }
  int q;
  int tot = 0;
  fin >> q;
  for (int i = 1; i <= q; i++) {
    int num;
    fin >> num;
    for (int j = 1; j <= num; j++) {
      int x;
      fin >> x;
      qt[++tot].id = i;
      qt[tot].u = edge[x].u;
      qt[tot].v = edge[x].v;
      qt[tot].val = edge[x].val;
    }
  }
  sort(qt + 1, qt + 1 + tot);
  sort(edge + 1, edge + 1 + m);
  int now = 1;
  for (int i = 1; i <= m; i++) {
    if (now > tot) break;
    int cnt = 0;
    while (qt[now].val == edge[i].val && now <= tot) {
      if (qt[now].id != qt[now - 1].id && qt[now - 1].val == qt[now].val) {
        del(cnt);
        cnt = 0;
      }
      int fax = findfa(qt[now].u);
      int fay = findfa(qt[now].v);
      if (fax == fay) {
        ans[qt[now].id] = 1;
      } else {
        int k = uni(qt[now].u, qt[now].v);
        cnt++;
      }
      now++;
    }
    del(cnt);
    cnt = 0;
    int rs = uni(edge[i].u, edge[i].v);
  }
  for (int i = 1; i <= q; i++) {
    if (ans[i])
      printf("NO\n");
    else
      printf("YES\n");
  }
}
