#include <bits/stdc++.h>
using namespace std;
int num[1000059], check, x, y, n, m, data[500069][4], d[500069], k, q,
    t[500069], aa[500069], bb[500069];
bool cmp(int x, int y) { return data[x][2] < data[y][2]; }
int root(int x) {
  if (d[x] < 0)
    return x;
  else
    return d[x] = root(d[x]);
}
void Union(int x, int y) {
  d[x] = d[x] + d[y];
  d[y] = x;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &data[i][0], &data[i][1], &data[i][2]);
    t[i] = i;
  }
  sort(t + 1, t + 1 + m, cmp);
  memset(d, -1, sizeof(d));
  for (int i = 1; i <= m; i++) {
    if (i > 1 && data[t[i]][2] == data[t[i - 1]][2]) continue;
    for (int j = i; j <= m && data[t[j]][2] == data[t[i]][2]; j++) {
      aa[t[j]] = root(data[t[j]][0]);
      bb[t[j]] = root(data[t[j]][1]);
    }
    for (int j = i; j <= m && data[t[j]][2] == data[t[i]][2]; j++) {
      x = root(data[t[j]][0]);
      y = root(data[t[j]][1]);
      if (x != y) {
        num[data[t[j]][2]]++;
        Union(x, y);
      }
    }
  }
  scanf("%d", &q);
  for (int te = 1; te <= q; te++) {
    scanf("%d", &k);
    for (int i = 1; i <= k; i++) scanf("%d", &t[i]);
    sort(t + 1, t + 1 + k, cmp);
    check = 1;
    for (int i = 1; i <= k; i++) {
      if (i > 1 && data[t[i]][2] == data[t[i - 1]][2]) continue;
      for (int j = i; j <= k && data[t[j]][2] == data[t[i]][2]; j++) {
        d[aa[t[j]]] = d[bb[t[j]]] = -1;
        if (j - i > num[data[t[i]][2]]) check = 0;
      }
      for (int j = i; j <= k && data[t[j]][2] == data[t[i]][2]; j++) {
        x = root(aa[t[j]]);
        y = root(bb[t[j]]);
        if (x != y) {
          Union(x, y);
        } else {
          check = 0;
        }
      }
    }
    if (check)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
