#include <bits/stdc++.h>
using namespace std;
const int N = 500200;
const int mod = 1e9 + 7;
int tmr, p[N], f[N], u[N], v[N], w[N], n, m, Q, k, t[N], fail[N];
vector<int> e[N];
vector<pair<int, int> > q[N];
inline int get(int x) {
  if (x == p[x]) return x;
  return p[x] = get(p[x]);
}
inline int get2(int x) {
  if (t[x] != tmr) t[x] = tmr, f[x] = p[x];
  if (f[x] == x) return x;
  return f[x] = get2(f[x]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) p[i] = i, f[i] = i;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &u[i], &v[i], &w[i]);
    e[w[i]].push_back(i);
  }
  scanf("%d", &Q);
  for (int i = 1; i <= Q; ++i) {
    scanf("%d", &k);
    for (int j = 1, x; j <= k; ++j) {
      scanf("%d", &x);
      q[w[x]].push_back(make_pair(i, x));
    }
  }
  for (int i = 1; i <= 500000; ++i) {
    sort(q[i].begin(), q[i].end());
    int last = 0;
    for (int j = 0; j < q[i].size(); ++j) {
      int id = q[i][j].second, ind = q[i][j].first;
      if (ind != last) tmr++;
      int a = u[id], b = v[id];
      a = get2(a), b = get2(b);
      if (a == b) fail[ind] = 1;
      f[a] = b;
      last = ind;
    }
    for (int j = 0; j < e[i].size(); ++j) {
      int id = e[i][j], a = u[id], b = v[id];
      a = get(a), b = get(b);
      if (a == b) continue;
      p[a] = b;
    }
  }
  for (int i = 1; i <= Q; ++i)
    if (!fail[i])
      puts("YES");
    else
      puts("NO");
  return 0;
}
