#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x;
}
struct edge {
  int f, t, l, id;
} w[N];
int n, m, u[N], v[N], fa[N], q;
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
bool ok[N];
bool cmp(edge a, edge b) { return a.l < b.l; }
vector<int> e[N];
int a[N], E, V, vis[N], C;
void dfs(int x) {
  if (vis[x] == C) return;
  vis[x] = C;
  V++;
  E += e[x].size();
  for (auto v : e[x]) dfs(v);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    w[i].f = read();
    w[i].t = read();
    w[i].l = read();
    u[i] = w[i].f;
    v[i] = w[i].t;
    w[i].id = i;
  }
  sort(w + 1, w + m + 1, cmp);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m;) {
    int flag = w[i].l, last = i;
    while (w[i].l == flag) {
      u[w[i].id] = find(w[i].f);
      v[w[i].id] = find(w[i].t);
      ok[w[i].id] = (find(w[i].f) != find(w[i].t)), i++;
    }
    while (last < i) fa[find(w[last].f)] = find(w[last].t), last++;
  }
  q = read();
  for (int i = 1; i <= q; i++) {
    int k = read();
    bool check = 1;
    for (int i = 1; i <= k; i++)
      if (!ok[a[i] = read()]) check = 0;
    if (!check) {
      puts("NO");
      continue;
    }
    for (int i = 1; i <= k; i++) {
      e[u[a[i]]].push_back(v[a[i]]);
      e[v[a[i]]].push_back(u[a[i]]);
    }
    C++;
    for (int i = 1; i <= k; i++) {
      if (vis[u[a[i]]] != C) {
        E = V = 0;
        dfs(u[a[i]]);
        if (E != (V - 1) * 2) check = 0;
      }
      if (vis[v[a[i]]] != C) {
        E = V = 0;
        dfs(v[a[i]]);
        if (E != (V - 1) * 2) check = 0;
      }
    }
    for (int i = 1; i <= k; i++) {
      e[u[a[i]]].clear();
      e[v[a[i]]].clear();
    }
    puts(check ? "YES" : "NO");
  }
  return 0;
}
