#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
const int M = 4 * N + 30 * N;
int p[N];
int find(int x) { return p[x] = p[x] == x ? x : find(p[x]); }
int u[N], v[N], w[N];
int to(int from, int id) { return u[id] == from ? v[id] : u[id]; }
vector<pair<int, vector<int>>> queries[N];
vector<int> adj[N];
int vis[N];
int qr[N];
int dfs(int u, int p = -1) {
  vis[u] = 1;
  for (int v : adj[u]) {
    if (v == p) continue;
    if (vis[v]) return 0;
    if (!dfs(v, u)) return 0;
  }
  return 1;
}
int stk[2 * N];
int top;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  iota(p, p + N, 0);
  vector<pair<int, int>> ord;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d", u + i, v + i, w + i);
    ord.emplace_back(w[i], i);
  }
  sort(begin(ord), end(ord));
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int k;
    scanf("%d", &k);
    vector<pair<int, int>> ed;
    while (k--) {
      int id;
      scanf("%d", &id);
      ed.emplace_back(w[id], id);
    }
    sort(begin(ed), end(ed));
    for (int a = 0; a < ed.size();) {
      int b = a;
      while (b < ed.size() && ed[b].first == ed[a].first) b++;
      qr[i]++;
      queries[ed[a].first].emplace_back(i, vector<int>(b - a, 0));
      for (int k = a; k < b; k++) {
        queries[ed[a].first].back().second[k - a] = (ed[k].second);
      }
      a = b;
    }
  }
  for (int i = 0; i < ord.size();) {
    int j = i;
    while (j < ord.size() && ord[j].first == ord[i].first) j++;
    int lv = ord[i].first;
    for (auto& p : queries[lv]) {
      bool ok = true;
      for (int id : p.second) {
        int x = u[id], y = v[id];
        x = find(x);
        y = find(y);
        if (x == y) {
          ok = false;
          break;
        }
        stk[top++] = x;
        stk[top++] = y;
        adj[x].push_back(y);
        adj[y].push_back(x);
      }
      if (!ok) {
        while (top > 0) {
          top--;
          adj[stk[top]].clear();
        }
        continue;
      }
      for (int id : p.second) {
        int x = u[id], y = v[id];
        x = find(x);
        y = find(y);
        if (!vis[x]) ok = ok && dfs(x);
      }
      while (top > 0) {
        top--;
        adj[stk[top]].clear();
        vis[stk[top]] = 0;
      }
      if (ok) {
        qr[p.first]--;
      }
    }
    for (int k = i; k < j; k++) {
      int id = ord[k].second;
      int x = find(u[id]);
      int y = find(v[id]);
      if (x != y) p[x] = y;
    }
    i = j;
  }
  for (int i = 0; i < q; i++) {
    if (!qr[i])
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
