#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 69;
int par[MAXN];
int deep[MAXN];
vector<int> g[MAXN];
int n, m;
bitset<MAXN> used;
struct edge {
  int fr, to, c, i;
};
bool cmp(edge a, edge b) { return a.c < b.c; }
edge e[MAXN];
edge con[MAXN];
int find_set(int v) {
  if (v == par[v]) return v;
  return par[v] = find_set(par[v]);
}
void union_sets(int a, int b) {
  a = find_set(a), b = find_set(b);
  if (a != b) {
    if (deep[a] < deep[b]) swap(a, b);
    par[b] = a;
    if (deep[a] == deep[b]) deep[a]++;
  }
}
struct kek {
  int num;
  vector<pair<int, int>> q;
};
vector<int> on;
vector<int> qr[MAXN];
vector<kek> d[MAXN];
string ans[MAXN];
bool dfs(int v, int p) {
  used[v] = 1;
  for (int to : g[v]) {
    if (p == to) continue;
    if (used[to]) {
      return 0;
    }
    if (!dfs(to, v)) return 0;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int fr, to, c;
    cin >> fr >> to >> c;
    fr--, to--;
    e[i] = {fr, to, c, i};
    con[i] = e[i];
  }
  sort(e, e + m, cmp);
  int i = 0;
  int cl = 1;
  for (int i = 0; i < n; ++i) par[i] = i;
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    ans[i] = "YES";
    int dl;
    cin >> dl;
    vector<pair<int, int>> kek(0);
    for (int j = 0; j < dl; ++j) {
      int r;
      cin >> r;
      r--;
      kek.push_back({con[r].c, r});
    }
    sort(kek.begin(), kek.end());
    int j = 0;
    while (j < dl) {
      int k = j;
      vector<pair<int, int>> z(0);
      while (k < dl && kek[j].first == kek[k].first) {
        z.push_back({con[kek[k].second].fr, con[kek[k].second].to});
        k++;
      }
      d[kek[j].first].push_back({i, z});
      j = k;
    }
  }
  while (i < m) {
    int j = i;
    while (j < m && e[i].c == e[j].c) {
      j++;
    }
    for (auto j : d[e[i].c]) {
      for (auto k : j.q) {
        int fr = k.first, to = k.second;
        fr = find_set(fr), to = find_set(to);
        g[fr].resize(0);
        g[to].resize(0);
        used[fr] = used[to] = 0;
      }
      for (auto k : j.q) {
        int fr = k.first, to = k.second;
        fr = find_set(fr), to = find_set(to);
        g[fr].push_back(to);
        g[to].push_back(fr);
      }
      bool ok = 1;
      for (auto k : j.q) {
        int fr = k.first, to = k.second;
        fr = find_set(fr), to = find_set(to);
        if (!used[fr]) {
          ok &= dfs(fr, -1);
        }
      }
      if (!ok) ans[j.num] = "NO";
    }
    for (int k = i; k < j; ++k) union_sets(e[k].fr, e[k].to);
    i = j;
  }
  for (int i = 0; i < q; ++i) cout << ans[i] << '\n';
  return 0;
}
