#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 100;
int n, m, a[N], b[N], c[N], p[N], q, p2[N];
vector<int> all[N];
vector<pair<int, int> > queries[N];
bool ok[N];
int findSet(int i) { return (i == p[i] ? i : p[i] = findSet(p[i])); }
int find2(int i) { return i == p2[i] ? i : p2[i] = find2(p2[i]); }
void solve(vector<pair<int, int> >& vec, int l, int r) {
  if (!ok[vec[l].second]) return;
  for (int z = l; z <= r; z++) {
    int idx = vec[z].first;
    int u = findSet(a[idx]);
    int v = findSet(b[idx]);
    p2[u] = u;
    p2[v] = v;
  }
  for (int z = l; z <= r; z++) {
    int idx = vec[z].first;
    int u = find2(findSet(a[idx]));
    int v = find2(findSet(b[idx]));
    if (u == v) {
      ok[vec[l].second] = 0;
      return;
    }
    p2[u] = v;
  }
}
void solve(vector<pair<int, int> >& vec) {
  for (int i = 0; i < vec.size(); ++i) {
    int j = i;
    while (j + 1 < vec.size() && vec[j].second == vec[j + 1].second) j++;
    solve(vec, i, j);
    i = j;
  }
}
int main() {
  scanf("%d", &n), scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d", &a[i]), scanf("%d", &b[i]), scanf("%d", &c[i]);
    --a[i], --b[i];
    all[c[i]].push_back(i);
  }
  for (int i = 0; i < n; ++i) p[i] = i;
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) ok[i] = 1;
  for (int z = 0; z < q; ++z) {
    int k;
    scanf("%d", &k);
    for (int i = 0; i < k; ++i) {
      int idx;
      scanf("%d", &idx);
      idx--;
      queries[c[idx]].push_back(pair<int, int>(idx, z));
    }
  }
  for (int w = 1; w < N; w++) {
    solve(queries[w]);
    for (int i = 0; i < all[w].size(); ++i) {
      int idx = all[w][i];
      p[findSet(a[idx])] = findSet(b[idx]);
    }
  }
  for (int z = 0; z < q; ++z)
    if (ok[z])
      puts("YES");
    else
      puts("NO");
}
