#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int N = 5e5 + 10;
inline unsigned long long read() {
  unsigned long long data = 0, w = 1;
  char ch = getchar();
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (ch <= '9' && ch >= '0') data = data * 10 + ch - 48, ch = getchar();
  return data * w;
}
inline void file() {
  freopen(
      "a"
      ".in",
      "r", stdin);
  freopen(
      "a"
      ".out",
      "w", stdout);
}
struct Dsu {
  int fa[N], cal[N], top;
  inline void init() {
    memset(fa, 0, sizeof(fa));
    top = 0;
  }
  int find(int x) { return fa[x] ? fa[x] = find(fa[x]) : x; }
  inline void rebuild() {
    while (top) fa[cal[top--]] = 0;
  }
  inline bool merge(int u, int v) {
    int fu = find(u), fv = find(v);
    if (fu != fv) cal[++top] = fu, fa[fu] = fv;
    return fu != fv;
  }
} dsu;
int n, m, q;
struct edge {
  int u, v, id;
};
vector<edge> E[N], F[N];
vector<edge>::iterator it;
int vis[N], a[N], b[N], w[N], e[N];
inline bool cmp(int i, int j) { return w[i] < w[j]; }
int main() {
  n = read();
  m = read();
  for (int i = 1, u, v; i <= m; i++) {
    u = read();
    v = read();
    w[i] = read();
    E[w[i]].push_back((edge){u, v, i});
  }
  for (int i = 1, fu, fv; i < N; i++) {
    for (it = E[i].begin(); it != E[i].end(); it++) {
      fu = dsu.find(it->u);
      fv = dsu.find(it->v);
      if (fu != fv) {
        vis[it->id] = 1;
        a[it->id] = it->u = fu;
        b[it->id] = it->v = fv;
        F[i].push_back(*it);
      }
    }
    for (it = E[i].begin(); it != E[i].end(); it++) dsu.merge(it->u, it->v);
  }
  dsu.rebuild();
  q = read();
  for (int i = 1, k, pd; i <= q; i++) {
    k = read();
    pd = 1;
    for (int j = 1; j <= k; j++) e[j] = read();
    for (int j = 1; j <= k; j++)
      if (!vis[e[j]]) {
        pd = 0;
        break;
      }
    if (pd) {
      sort(e + 1, e + k + 1, cmp);
      for (int j = k, p; j; j = p) {
        p = j;
        while (p && w[e[p]] == w[e[j]]) pd &= dsu.merge(a[e[p]], b[e[p]]), p--;
        dsu.rebuild();
      }
    }
    puts(pd ? "YES" : "NO");
  }
  return 0;
}
