#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 7;
int n, m, q;
int u[maxn], v[maxn], w[maxn];
vector<pair<int, int> > o[maxn];
vector<int> e[maxn];
bool answer[maxn];
int tail = 0;
int anc[maxn], sz[maxn];
int _u[maxn];
int find(int x) {
  if (x == anc[x]) return x;
  return find(anc[x]);
}
bool add(int u, int v) {
  u = find(u);
  v = find(v);
  if (u == v) return false;
  if (sz[u] > sz[v]) swap(u, v);
  tail++;
  anc[u] = v;
  sz[v] += sz[u];
  _u[tail] = u;
  return true;
}
void goback() {
  sz[find(_u[tail])] -= sz[_u[tail]];
  anc[_u[tail]] = _u[tail];
  tail--;
}
int main(int argc, char **argv) {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u[i], &v[i], &w[i]);
    e[w[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) anc[i] = i, sz[i] = 1;
  scanf("%d", &q);
  for (int _ = 1; _ <= q; _++) {
    int len, idx;
    scanf("%d", &len);
    for (int i = 1; i <= len; i++) {
      scanf("%d", &idx);
      o[w[idx]].push_back(pair<int, int>(idx, _));
    }
    answer[_] = true;
  }
  for (int _ = 1; _ < maxn; _++) {
    if (e[_].size() == 0) continue;
    int sz = o[_].size();
    for (int i = 0; i < sz; i++) {
      int j = i;
      while (j < sz && o[_][i].second == o[_][j].second) j++;
      j--;
      bool flag = true;
      int cnt = 0;
      for (int k = i; k <= j; k++) {
        if (!add(u[o[_][k].first], v[o[_][k].first]))
          flag = false;
        else
          cnt++;
      }
      for (int k = 1; k <= cnt; k++) goback();
      if (!flag) answer[o[_][i].second] = false;
      i = j;
    }
    for (auto &p : e[_]) add(u[p], v[p]);
  }
  for (int i = 1; i <= q; i++)
    if (answer[i])
      printf("YES\n");
    else
      printf("NO\n");
  return 0;
}
