#include <bits/stdc++.h>
using namespace std;
const int MAX = 5e5 + 5;
vector<int> edges[MAX];
vector<pair<int, int> > queries[MAX];
int par[MAX];
int tmpparent[MAX];
int a[MAX], b[MAX], c[MAX];
int ans[MAX];
int find(int x) {
  if (par[x] == x) {
    return x;
  }
  return (par[x] = find(par[x]));
}
int tmpfind(int x) {
  if (tmpparent[x] == x) {
    return x;
  }
  return (tmpparent[x] = tmpfind(tmpparent[x]));
}
void solve(int ind, int l, int r) {
  for (int i = l; i <= r; i++) {
    int x = find(a[queries[ind][i].second]);
    int y = find(b[queries[ind][i].second]);
    if (x == y) {
      ans[queries[ind][i].first] = 0;
      return;
    }
    tmpparent[x] = x;
    tmpparent[y] = y;
  }
  for (int i = l; i <= r; i++) {
    int x = find(a[queries[ind][i].second]);
    int y = find(b[queries[ind][i].second]);
    x = tmpfind(x);
    y = tmpfind(y);
    if (x == y) {
      ans[queries[ind][i].first] = 0;
      return;
    }
    tmpparent[x] = y;
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
    edges[c[i]].push_back(i);
  }
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int sz;
    scanf("%d", &sz);
    ans[i] = 1;
    for (int j = 0; j < sz; j++) {
      int val;
      scanf("%d", &val);
      queries[c[val]].push_back(make_pair(i, val));
    }
  }
  for (int i = 1; i <= n; i++) {
    par[i] = i;
  }
  for (int i = 0; i < MAX; i++) {
    if (edges[i].size() == 0) {
      continue;
    }
    sort(queries[i].begin(), queries[i].end());
    for (int j = 0; j < queries[i].size(); j++) {
      int k = j;
      while (k < queries[i].size() &&
             queries[i][k].first == queries[i][j].first) {
        k++;
      }
      solve(i, j, k - 1);
      j = k - 1;
    }
    for (int j = 0; j < edges[i].size(); j++) {
      int x = find(a[edges[i][j]]);
      int y = find(b[edges[i][j]]);
      par[x] = y;
    }
  }
  for (int i = 1; i <= q; i++) {
    if (ans[i]) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}
