#include <bits/stdc++.h>
using namespace std;
int fa[500010], siz[500010];
class opt {
 public:
  int x, y, fx, fy, sx, sy;
};
vector<opt> O;
int getf(int x) { return x == fa[x] ? x : getf(fa[x]); }
bool merge(int x, int y) {
  x = getf(x);
  y = getf(y);
  if (x == y) return 0;
  if (siz[x] > siz[y]) swap(x, y);
  O.push_back((opt){x, y, fa[x], fa[y], siz[x], siz[y]});
  fa[x] = y;
  siz[y] += siz[x];
  return 1;
}
void rollback() {
  opt tmp = O.back();
  O.pop_back();
  fa[tmp.x] = tmp.fx;
  fa[tmp.y] = tmp.fy;
  siz[tmp.x] = tmp.sx;
  siz[tmp.y] = tmp.sy;
}
class edge {
 public:
  int s, e, w;
} g[500010];
vector<int> qe[500010], eid[500010];
vector<int> mdf[500010];
bool ans[500010];
int n, m, q, pos[500010];
int comp(int a, int b) { return g[a].w < g[b].w; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    siz[i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &g[i].s, &g[i].e, &g[i].w);
    eid[g[i].w].push_back(i);
  }
  scanf("%d", &q);
  for (int i = 1, ti; i <= q; i++) {
    ans[i] = 1;
    scanf("%d", &ti);
    for (int j = 0, tj; j < ti; j++) {
      scanf("%d", &tj);
      int w = g[tj].w;
      if (mdf[w].empty() || mdf[w].back() != i) mdf[w].push_back(i);
      qe[i].push_back(tj);
    }
    sort(qe[i].begin(), qe[i].end(), comp);
  }
  for (int i = 1; i <= 500000; i++) {
    for (int p : mdf[i]) {
      if (!ans[p]) continue;
      while (pos[p] < qe[p].size() && g[qe[p][pos[p]]].w == i) {
        if (!merge(g[qe[p][pos[p]]].s, g[qe[p][pos[p]]].e)) {
          ans[p] = 0;
          break;
        }
        pos[p]++;
      }
      while (!O.empty()) rollback();
    }
    for (int p : eid[i]) merge(g[p].s, g[p].e);
    O.clear();
  }
  for (int i = 1; i <= q; i++) {
    if (ans[i])
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
