#include <bits/stdc++.h>
using namespace std;
namespace fastIO {
bool IOerror = 0;
inline char nc() {
  static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;
  if (p1 == pend) {
    p1 = buf;
    pend = buf + fread(buf, 1, 100000, stdin);
    if (pend == p1) {
      IOerror = 1;
      return -1;
    }
  }
  return *p1++;
}
inline bool blank(char ch) {
  return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
inline long long read() {
  bool sign = 0;
  char ch = nc();
  long long x = 0;
  for (; blank(ch); ch = nc())
    ;
  if (IOerror) return 0;
  if (ch == '-') sign = 1, ch = nc();
  for (; ch >= '0' && ch <= '9'; ch = nc()) x = x * 10 + ch - '0';
  if (sign) x = -x;
  return x;
}
};  // namespace fastIO
using namespace fastIO;
struct edge {
  long long x, y, z;
} e[1000010];
struct query {
  long long x, y, z, id;
} q[1000010];
long long now = 0;
bool cmp(edge e1, edge e2) { return e1.z < e2.z; }
bool cmp1(query q1, query q2) {
  return q1.z != q2.z ? q1.z < q2.z : q1.id < q2.id;
}
long long fa1[1000010], fa2[1000010], ans[1000010];
long long find1(long long x) {
  return x == fa1[x] ? x : fa1[x] = find1(fa1[x]);
}
long long tim = 0;
long long las[1000010];
long long find2(long long x) {
  if (las[x] != tim) {
    fa2[x] = fa1[x];
    las[x] = tim;
  }
  return x == fa2[x] ? x : fa2[x] = find2(fa2[x]);
}
signed main() {
  long long n = read(), m = read();
  for (long long i = 1; i <= m; i++) {
    e[i].x = read(), e[i].y = read(), e[i].z = read();
  }
  long long qq = read();
  for (long long i = 1; i <= qq; i++) {
    long long k = read();
    for (long long j = 1; j <= k; j++) {
      long long x = read();
      q[++now] = query{e[x].x, e[x].y, e[x].z, i};
    }
  }
  sort(e + 1, e + 1 + m, cmp);
  sort(q + 1, q + 1 + now, cmp1);
  for (long long i = 1; i <= n; i++) fa1[i] = i, fa2[i] = i;
  long long now1 = 1, now2 = 1;
  for (long long i = 1; i <= now;) {
    while (e[now1].z < q[i].z && now1 <= m) {
      long long aa = find1(e[now1].x), bb = find1(e[now1].y);
      if (aa != bb) fa1[aa] = bb;
      now1++;
    }
    while (q[now2].z == q[i].z && now2 <= now) {
      if (now2 == i || q[now2].id != q[now2 - 1].id) tim++;
      long long aa = find2(q[now2].x), bb = find2(q[now2].y);
      if (aa == bb)
        ans[q[now2].id] = 1;
      else
        fa2[aa] = bb;
      now2++;
    }
    i = now2;
  }
  for (long long i = 1; i <= qq; i++) puts(ans[i] ? "NO" : "YES");
  return 0;
}
