#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
struct edge {
  int from, to, val, id;
  friend bool operator<(const edge &a, const edge &b) { return a.val < b.val; }
} a[maxn];
struct queryEdge {
  int from, to, id;
};
vector<queryEdge> v[maxn];
int fa[maxn], siz[maxn], stp[maxn], top, n, m, q;
bool ans[maxn];
int find(int x) {
  while (x != fa[x]) x = fa[x];
  return x;
}
bool baba(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx == fy) return false;
  if (siz[fx] > siz[fy]) swap(fx, fy);
  siz[fy] += siz[fx];
  fa[fx] = fy;
  stp[++top] = fx;
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &a[i].from, &a[i].to, &a[i].val);
    a[i].id = i;
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      int id;
      scanf("%d", &id);
      v[a[id].val].push_back({a[id].from, a[id].to, i});
    }
  }
  sort(a + 1, a + 1 + m);
  for (int i = 1; i <= n; i++) {
    fa[i] = i, siz[i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int val = a[i].val;
    top = 0;
    for (int j = 0; j < v[val].size(); j++) {
      if (j != 0 && v[val][j].id != v[val][j - 1].id) {
        while (top) {
          int fx = stp[top];
          top--;
          siz[fa[fx]] -= siz[fx];
          fa[fx] = fx;
        }
      }
      if (ans[v[val][j].id] == 1) continue;
      if (!baba(v[val][j].from, v[val][j].to)) {
        ans[v[val][j].id] = 1;
      }
    }
    baba(a[i].from, a[i].to);
    for (int j = i + 1; j <= m && a[j].val == a[j - 1].val; j++, i++) {
      baba(a[j].from, a[j].to);
    }
  }
  for (int i = 1; i <= q; i++) {
    if (ans[i])
      puts("NO");
    else
      puts("YES");
  }
}
