#include <bits/stdc++.h>
using namespace std;
const int M = 5e5 + 10;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const int bit = 32;
const double pi = acos(-1.0);
int f[M], siz[M], d[M], ans[M];
struct edg {
  int x, y, z;
  bool operator<(const edg &a) const { return z < a.z; }
} w[M];
struct node {
  int x, y, num;
  bool operator<(const node &a) const { return num < a.num; }
};
vector<node> v[M];
void inti() {
  for (int i = 0; i < M; i++) {
    f[i] = i;
    siz[i] = 1;
    ans[i] = 1;
  }
}
int fi(int x) { return x == f[x] ? x : fi(f[x]); }
stack<int> s;
bool mergy(int x, int y) {
  int xx = fi(x), yy = fi(y);
  if (xx == yy) return false;
  if (siz[xx] > siz[yy]) swap(xx, yy);
  siz[yy] += siz[xx];
  f[xx] = yy;
  s.push(xx);
  return true;
}
int main() {
  int n, m;
  inti();
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &w[i].x, &w[i].y, &w[i].z);
  }
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 1, x; j <= k; j++) {
      scanf("%d", &x);
      node st;
      st.num = i;
      st.x = w[x].x;
      st.y = w[x].y;
      v[w[x].z].push_back(st);
    }
  }
  sort(w + 1, w + 1 + m);
  for (int i = 0; i < M; i++) {
    sort(v[i].begin(), v[i].end());
  }
  for (int i = 1; i <= m;) {
    int c = w[i].z;
    while (s.size()) s.pop();
    for (int j = 0; j < v[c].size(); j++) {
      if (!ans[v[c][j].num]) continue;
      if (j > 0 && v[c][j - 1].num != v[c][j].num) {
        while (s.size()) {
          int c = s.top();
          f[c] = c;
          s.pop();
        }
      }
      if (!mergy(v[c][j].x, v[c][j].y)) ans[v[c][j].num] = 0;
    }
    while (s.size()) {
      int c = s.top();
      f[c] = c;
      s.pop();
    }
    while (w[i].z == c) {
      int sss = mergy(w[i].x, w[i].y);
      i++;
    }
  }
  for (int i = 1; i <= q; i++) {
    if (ans[i]) {
      puts("YES");
    } else
      puts("NO");
  }
  return 0;
}
