#include <bits/stdc++.h>
using namespace std;
const long long inf = INT_MAX, df = 1e6 + 7;
long long head[df], fa[df], n, m, q, k, top;
struct edge {
  long long x, y, w, u, v, id;
} e[df << 1], sta[df];
bool cmp1(edge st, edge ch) { return st.w < ch.w; }
bool cmp2(edge st, edge ch) { return st.id < ch.id; }
inline long long read() {
  long long x = 0, y = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') y = (ch == '-') ? -1 : 1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * y;
}
long long upd(long long x) { return (fa[x] == x) ? x : fa[x] = upd(fa[x]); }
int main() {
  n = read(), m = read();
  for (long long i = (1); i <= (n); ++i) fa[i] = i;
  for (long long i = (1); i <= (m); ++i)
    e[i].u = read(), e[i].v = read(), e[i].w = read(), e[i].id = i;
  sort(e + 1, e + m + 1, cmp1);
  e[0].w = -1;
  for (long long i = 1; i <= m;) {
    long long j = i;
    do {
      e[j].x = upd(e[j].u);
      e[j].y = upd(e[j].v);
      j++;
    } while (e[j].w == e[j - 1].w && j <= m);
    while (i < j) {
      while (upd(e[i].u) == upd(e[i].v) && i < j) ++i;
      if (i < j) fa[upd(e[i].u)] = upd(e[i].v);
    }
  }
  sort(e + 1, e + m + 1, cmp2);
  for (long long i = (1); i <= (n); ++i) fa[i] = i;
  q = read();
  while (q--) {
    k = read();
    long long t = 0;
    top = 0;
    for (long long i = (1); i <= (k); ++i)
      t = read(), sta[++top] = (edge){e[t].x, e[t].y, e[t].w};
    sort(sta + 1, sta + top + 1, cmp1);
    long long op = 1;
    for (long long i = 1; i <= k && op;) {
      if (sta[i].x == sta[i].y) {
        op = 0;
        break;
      }
      fa[upd(sta[i].x)] = upd(sta[i].y);
      long long j = i + 1;
      while (j <= k && sta[j].w == sta[i].w) {
        if (upd(sta[j].x) == upd(sta[j].y)) {
          op = 0;
          break;
        }
        fa[upd(sta[j].x)] = upd(sta[j].y);
        ++j;
      }
      while (i < j) fa[sta[i].x] = sta[i].x, fa[sta[i].y] = sta[i].y, ++i;
    }
    puts((op == 1) ? "YES" : "NO");
  }
}
