#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > qr[500005];
vector<int> edges[500005];
int ans[500005], u[500005], v[500005], w[500005];
int par1[500005], par2[500005], qr_node[500005], T;
int find1(int x) {
  if (par1[x] != x) return par1[x] = find1(par1[x]);
  return x;
}
int find2(int x) {
  if (qr_node[x] != T) {
    qr_node[x] = T, par2[x] = par1[x];
  };
  if (par2[x] != x) return par2[x] = find2(par2[x]);
  return x;
}
int main() {
  int n, m, q, k, idx, max_w = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) par1[i] = par2[i] = i;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u[i], &v[i], &w[i]);
    max_w = max(max_w, w[i]);
    edges[w[i]].push_back(i);
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      scanf("%d", &idx);
      qr[w[idx]].push_back(make_pair(i, idx));
    }
  }
  for (int i = 1; i <= max_w; i++) {
    for (int j = 0; j < qr[i].size(); j++) {
      if (j == 0 || qr[i][j].first != qr[i][j - 1].first) T++;
      int x = find2(u[qr[i][j].second]), y = find2(v[qr[i][j].second]);
      if (x == y) ans[qr[i][j].first] = 1;
      par2[y] = par2[x];
    }
    for (int j = 0; j < edges[i].size(); j++) {
      int x = find1(u[edges[i][j]]), y = find1(v[edges[i][j]]);
      par1[y] = par1[x];
    }
  }
  for (int i = 1; i <= q; i++) {
    if (ans[i])
      printf("NO\n");
    else
      printf("YES\n");
  }
  return 0;
}
