#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void init(T& x) {
  x = 0;
  char ch = getchar();
  bool t = 0;
  for (; ch > '9' || ch < '0'; ch = getchar())
    if (ch == '-') t = 1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = (x << 1) + (x << 3) + (ch - 48);
  if (t) x = -x;
  return;
}
int n, m;
const int N = 5e5 + 10;
struct edge {
  int u, v, val, id;
  inline bool operator<(const edge B) const { return val < B.val; }
} a[N];
int belu[N], belv[N], pos[N];
int q, fa[N];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
inline void MST() {
  int u, v, w;
  for (int i = 1; i <= m; ++i) {
    init(u), init(v), init(w);
    a[i] = (edge){u, v, w, i};
  }
  sort(a + 1, a + 1 + m);
  for (int i = 1; i <= m; ++i) pos[a[i].id] = i;
  for (int i = 1; i <= n; ++i) fa[i] = i;
  int r;
  for (int l = 1; l <= m; l = r) {
    r = l;
    while (a[r].val == a[l].val && r <= m) {
      u = a[r].u, v = a[r].v;
      belu[r] = find(u);
      belv[r] = find(v);
      ++r;
    }
    r = l;
    while (a[r].val == a[l].val && r <= m) {
      u = a[r].u, v = a[r].v;
      int fx = find(u), fy = find(v);
      if (fx != fy) fa[fx] = fy;
      ++r;
    }
  }
  return;
}
int que[N];
int main() {
  init(n), init(m);
  MST();
  init(q);
  for (int i = 1; i <= n; ++i) fa[i] = i;
  for (int i = 1; i <= q; ++i) {
    int K;
    init(K);
    for (int j = 1; j <= K; ++j) init(que[j]), que[j] = pos[que[j]];
    sort(que + 1, que + 1 + K);
    int r;
    bool flag = 1;
    for (int l = 1; l <= K; l = r) {
      r = l;
      while (r <= K && a[que[r]].val == a[que[l]].val) {
        int u = a[que[r]].u, v = a[que[r]].v;
        int blu = belu[que[r]], blv = belv[que[r]];
        fa[blu] = blu, fa[blv] = blv;
        fa[u] = blu, fa[v] = blv;
        ++r;
      }
      r = l;
      while (r <= K && a[que[l]].val == a[que[r]].val) {
        int u = a[que[r]].u, v = a[que[r]].v;
        int fx = find(u), fy = find(v);
        if (fx == fy) {
          flag = 0;
          break;
        }
        fa[fx] = fy;
        ++r;
      }
      if (!flag) break;
    }
    if (flag)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
