#include <bits/stdc++.h>
using namespace std;
int n, a[5000];
const int Maxn = 500100;
tuple<int, int, int> ed[Maxn];
vector<pair<int, int> > gg[Maxn];
vector<pair<int, int> > go[Maxn];
int p[Maxn], sz[Maxn];
stack<pair<int, int> > st;
int flag[Maxn];
int get(int a) {
  if (p[a] != a) return get(p[a]);
  return a;
}
void un(int a, int b) {
  a = get(a);
  b = get(b);
  if (a == b) return;
  if (sz[a] > sz[b]) swap(a, b);
  p[a] = b;
  sz[b] += sz[a];
  st.push(make_pair(a, b));
}
void undo() {
  pair<int, int> tmp = st.top();
  st.pop();
  p[tmp.first] = tmp.first;
  sz[tmp.second] -= sz[tmp.first];
}
int main() {
  int n, m, maxw = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    --a, --b;
    maxw = max(maxw, c);
    gg[c].push_back(make_pair(a, b));
    ed[i] = make_tuple(c, a, b);
  }
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int l;
    scanf("%d", &l);
    for (int j = 0; j < l; j++) {
      int tmp;
      scanf("%d", &tmp);
      tmp--;
      go[get<0>(ed[tmp])].push_back(make_pair(i, tmp));
    }
  }
  for (int i = 0; i < n; ++i) p[i] = i, sz[i] = 1;
  for (int i = 1; i <= maxw; ++i) {
    sort(go[i].begin(), go[i].end());
    auto k = go[i].begin();
    int j = 0;
    while (j < q) {
      bool flag2 = false;
      int cnt = 0;
      if (k == go[i].end()) break;
      while (k != go[i].end() && k->first == j) {
        int a = get<1>(ed[k->second]);
        int b = get<2>(ed[k->second]);
        if (get(a) == get(b)) {
          flag[k->first] = 1;
          flag2 = 1;
          break;
        } else {
          cnt++;
          un(get(a), get(b));
          k++;
        }
      }
      while (cnt--) undo();
      if (flag2)
        while (k != go[i].end() && k->first == j) k++;
      if (k != go[i].end()) j = k->first;
    }
    for (auto e : gg[i]) un(e.first, e.second);
  }
  for (int i = 0; i < q; i++)
    if (!flag[i])
      puts("YES");
    else
      puts("NO");
  return 0;
}
