#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 100;
int T;
int n, m;
struct edge {
  int u, v, w;
};
edge E[maxn];
vector<int> E_value[maxn];
vector<pair<int, int> > H[maxn];
int tt[maxn];
int fa1[maxn];
int fa2[maxn];
bool ans[maxn];
int Find1(int x) { return x == fa1[x] ? x : fa1[x] = Find1(fa1[x]); }
int Find2(int x) {
  if (tt[x] != T) {
    tt[x] = T;
    fa2[x] = fa1[x];
  }
  return x == fa2[x] ? x : fa2[x] = Find2(fa2[x]);
}
int main() {
  int maxn = -1;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &E[i].u, &E[i].v, &E[i].w);
    E_value[E[i].w].push_back(i);
    maxn = max(maxn, E[i].w);
  }
  int Q;
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    ans[i] = false;
    int t;
    scanf("%d", &t);
    while (t--) {
      int x;
      scanf("%d", &x);
      H[E[x].w].push_back(make_pair(i, x));
    }
  }
  T = 0;
  for (int i = 1; i <= n; i++) {
    fa1[i] = i;
    tt[i] = 0;
  }
  for (int i = 1; i <= maxn; i++) {
    int len = H[i].size();
    sort(H[i].begin(), H[i].end());
    for (int j = 0; j < len; j++) {
      if (j == 0 || H[i][j].first != H[i][j - 1].first) T++;
      int x = E[H[i][j].second].u;
      int y = E[H[i][j].second].v;
      int xx = Find2(x);
      int yy = Find2(y);
      if (xx == yy) {
        ans[H[i][j].first] = true;
      } else {
        fa2[xx] = yy;
      }
    }
    int len2 = E_value[i].size();
    for (int j = 0; j < len2; j++) {
      int x = E[E_value[i][j]].u;
      int y = E[E_value[i][j]].v;
      int xx = Find1(x);
      int yy = Find1(y);
      if (xx != yy) {
        fa1[xx] = yy;
      }
    }
  }
  for (int i = 1; i <= Q; i++) {
    if (!ans[i])
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
