#include <bits/stdc++.h>
using namespace std;
const int N = 500500;
const long long INF = (long long)1e18;
int n, m, q, fa[N], dep[N], ans[N], vis[N];
vector<int> T;
struct edge {
  int u, v, w;
  vector<int> id;
  bool operator<(const edge &x) const { return w < x.w; }
} E[N];
struct node {
  int x, y, fy, dx;
} sta[N];
int top;
vector<edge> Q[N];
int find(int x) {
  while (fa[x] != x) x = fa[x];
  return x;
}
int Union(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return 0;
  if (dep[x] < dep[y]) swap(x, y);
  sta[++top].x = x;
  sta[top].y = y;
  sta[top].fy = fa[y];
  sta[top].dx = dep[x];
  dep[x] += (dep[x] == dep[y]);
  fa[y] = x;
  return 1;
}
int main() {
  ios ::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) fa[i] = i, dep[i] = 1;
  for (int i = 1; i <= m; i++) {
    cin >> E[i].u >> E[i].v >> E[i].w;
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int k;
    cin >> k;
    ans[i] = 1;
    for (int j = 1; j <= k; j++) {
      int t;
      cin >> t;
      E[t].id.push_back(i);
    }
  }
  sort(E + 1, E + m + 1);
  int pos = 1;
  for (int i = 1; i <= m; i = pos + 1) {
    pos = i;
    while (pos <= m && E[pos].w == E[i].w) {
      pos++;
    }
    pos--;
    T.clear();
    for (int j = i; j <= pos; j++) {
      for (auto id : E[j].id) {
        Q[id].push_back(E[j]);
        if (vis[id] != i) {
          vis[id] = i;
          T.push_back(id);
        }
      }
    }
    for (auto j : T) {
      if (!Q[j].size()) continue;
      top = 0;
      for (auto e : Q[j]) {
        int u = e.u, v = e.v;
        if (!Union(u, v)) {
          ans[j] = 0;
          break;
        }
      }
      while (top) {
        dep[sta[top].x] = sta[top].dx;
        fa[sta[top].y] = sta[top].fy;
        top--;
      }
      Q[j].clear();
    }
    for (int j = i; j <= pos; j++) Union(E[j].u, E[j].v);
  }
  for (int i = 1; i <= q; i++) {
    ans[i] ? puts("YES") : puts("NO");
  }
  return 0;
}
