#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
vector<pair<int, int> > add[500009];
vector<pair<int, pair<int, int> > > query[500009];
int ata[500009], ans[500009], sz[500009];
pair<int, pair<int, int> > arr[500009];
int tap(int x) {
  if (ata[x] == x) return x;
  return tap(ata[x]);
}
stack<pair<int, pair<int, int> > > st;
int cnt;
void merge(int type, int x, int y) {
  if ((x = tap(x)) == (y = tap(y))) return;
  if (sz[y] > sz[x]) swap(x, y);
  sz[x] += sz[y];
  ata[y] = x;
  if (type) cnt++, st.push(make_pair(y, make_pair(x, sz[y])));
}
void backup(int x) {
  while (x--) {
    ata[st.top().first] = st.top().first;
    sz[st.top().second.first] -= st.top().second.second;
    st.pop();
  }
}
void solve(pair<int, pair<int, int> > x) {
  int u = x.second.first;
  int v = x.second.second;
  if (tap(u) == tap(v)) ans[x.first] = 0;
  merge(1, u, v);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    add[w].push_back(make_pair(u, v));
    arr[i] = make_pair(w, make_pair(u, v));
  }
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      int x;
      scanf("%d", &x);
      query[arr[x].first].push_back(make_pair(i, arr[x].second));
    }
    ans[i] = 1;
  }
  for (int i = 1; i <= n; i++) ata[i] = i, sz[i] = 1;
  for (int i = 1; i < 500009; i++) {
    int last = -1;
    for (__typeof((query[i]).begin()) it = (query[i]).begin();
         it != (query[i]).end(); it++) {
      if (last != it->first) {
        backup(cnt);
        cnt = 0;
        last = it->first;
      }
      solve(*it);
    }
    backup(cnt);
    cnt = 0;
    for (__typeof((add[i]).begin()) it = (add[i]).begin(); it != (add[i]).end();
         it++)
      merge(0, it->first, it->second);
  }
  for (int i = 1; i <= q; i++) {
    if (ans[i])
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
