#include <bits/stdc++.h>
using namespace std;
FILE *in, *out;
int N, M, K;
pair<pair<int, int>, int> ar[500100];
vector<vector<int> > eg(500100);
vector<vector<pair<int, int> > > qe(500100);
int color[500100];
int color2[500100];
int mark[500100];
int findx(int p) {
  if (color[p] == p) return p;
  color[p] = findx(color[p]);
  return color[p];
}
int find2(int p) {
  if (color2[p] == p) return p;
  color2[p] = find2(color2[p]);
  return color2[p];
}
int read() {
  int i, j, k;
  int x, y;
  cin >> N >> M;
  for (i = 1; i <= M; i++) {
    cin >> ar[i].first.first >> ar[i].first.second >> ar[i].second;
    eg[ar[i].second].push_back(i);
  }
  cin >> K;
  for (i = 0; i < K; i++) {
    cin >> k;
    for (j = 0; j < k; j++) {
      cin >> x;
      qe[ar[x].second].push_back(make_pair(i, x));
    }
  }
  for (i = 1; i <= N; i++) color[i] = i;
  for (i = 1; i < 500100; i++) {
    if ((int)(qe[i].size())) sort(qe[i].begin(), qe[i].end());
    for (j = 0; j < (int)(qe[i].size()); j++) {
      if (j != 0 && qe[i][j].first == qe[i][j - 1].first) continue;
      for (k = j; k < (int)(qe[i].size()) && qe[i][k].first == qe[i][j].first;
           k++) {
        x = ar[qe[i][k].second].first.first;
        y = ar[qe[i][k].second].first.second;
        color2[findx(x)] = findx(x);
        color2[findx(y)] = findx(y);
      }
      for (k = j; k < (int)(qe[i].size()) && qe[i][k].first == qe[i][j].first;
           k++) {
        x = ar[qe[i][k].second].first.first;
        y = ar[qe[i][k].second].first.second;
        if (find2(findx(x)) == find2(findx(y))) {
          mark[qe[i][k].first] = 1;
          break;
        }
        color2[find2(findx(x))] = find2(findx(y));
      }
    }
    for (j = 0; j < (int)(eg[i].size()); j++) {
      x = ar[eg[i][j]].first.first;
      y = ar[eg[i][j]].first.second;
      color[findx(x)] = findx(y);
    }
  }
  for (i = 0; i < K; i++) {
    if (mark[i])
      printf("NO\n");
    else
      printf("YES\n");
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  in = stdin;
  out = stdout;
  read();
  return 0;
}
