#include <bits/stdc++.h>
using namespace std;
char getc() {
  char c = getchar();
  while ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && (c < '0' || c > '9'))
    c = getchar();
  return c;
}
int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); }
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return x * f;
}
int n, m, q, p[500010], ans[500010], cur[500010], v[500010];
int fa[500010], size[500010], stk_id[500010 << 1], stk_fa[500010 << 1],
    stk_size[500010 << 1];
vector<int> id[500010], pos[500010];
struct data {
  int x, y, z;
  bool operator<(const data& a) const { return z < a.z; }
} edge[500010], e[500010];
int find(int x) { return fa[x] == x ? x : find(fa[x]); }
bool cmp(const int& x, const int& y) { return edge[x].z < edge[y].z; }
signed main() {
  n = read(), m = read();
  for (int i = 1; i <= m; i++)
    edge[i].x = read(), edge[i].y = read(), v[i] = edge[i].z = read();
  sort(v + 1, v + m + 1);
  int t = unique(v + 1, v + m + 1) - v - 1;
  q = read();
  for (int i = 1; i <= q; i++) {
    int m = read();
    ans[i] = 1;
    while (m--) id[i].push_back(read());
    sort(id[i].begin(), id[i].end(), cmp);
    for (int j = 0; j < id[i].size(); j++) {
      int x = lower_bound(v + 1, v + t + 1, edge[id[i][j]].z) - v;
      if (!j || edge[id[i][j]].z != edge[id[i][j - 1]].z) pos[x].push_back(i);
    }
  }
  for (int i = 1; i <= m; i++) e[i] = edge[i];
  sort(edge + 1, edge + m + 1);
  for (int i = 1; i <= n; i++) fa[i] = i, size[i] = 1;
  int u = 0;
  for (int i = 1; i <= m; i++) {
    int t = i;
    u++;
    while (t < m && edge[t + 1].z == edge[i].z) t++;
    for (int j = 0; j < pos[u].size(); j++) {
      int x = pos[u][j];
      int top = 0;
      while (ans[x] && cur[x] < id[x].size() &&
             e[id[x][cur[x]]].z == edge[i].z) {
        int p = find(e[id[x][cur[x]]].x), q = find(e[id[x][cur[x]]].y);
        if (size[p] < size[q]) swap(p, q);
        if (p == q)
          ans[x] = 0;
        else {
          top++;
          stk_id[top] = p;
          stk_size[top] = size[p];
          stk_fa[top] = p;
          top++;
          stk_id[top] = q;
          stk_size[top] = size[q];
          stk_fa[top] = q;
          fa[q] = p;
          size[p] += size[q];
        }
        cur[x]++;
      }
      while (top)
        fa[stk_id[top]] = stk_fa[top], size[stk_id[top]] = stk_size[top], top--;
    }
    for (int j = i; j <= t; j++) {
      int p = find(edge[j].x), q = find(edge[j].y);
      if (size[p] < size[q]) swap(p, q);
      if (p != q) fa[q] = p, size[p] += size[q];
    }
    i = t;
  }
  for (int i = 1; i <= q; i++)
    if (ans[i])
      puts("YES");
    else
      puts("NO");
  return 0;
}
