#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
struct Edge {
  int u, v, w;
  friend bool operator<(Edge a1, Edge a2) { return a1.w < a2.w; }
};
struct query {
  vector<int> vec;
  int id;
};
Edge edges[maxn];
vector<Edge> mst;
vector<query> qedge[maxn];
vector<int> vec, del, edge[maxn];
int fa[maxn], vis[maxn], ans[maxn];
bool cmp(int a, int b) { return edges[a].w < edges[b].w; }
int find_fa(int u) { return fa[u] == u ? u : fa[u] = find_fa(fa[u]); }
bool dfs(int u, int fa) {
  int i, j, k;
  vis[u] = 1;
  for (i = 0; i < edge[u].size(); i++) {
    int v = edge[u][i];
    if (v == fa) continue;
    if (vis[v]) return 1;
    if (dfs(v, u)) return 1;
  }
  return 0;
}
int main() {
  int i, j, k;
  int n, m, q;
  for (i = 1; i < maxn; i++) fa[i] = i, ans[i] = 1;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &edges[i].u, &edges[i].v, &edges[i].w);
    mst.push_back((Edge){edges[i].u, edges[i].v, edges[i].w});
  }
  mst.push_back((Edge){0, 0, 0});
  sort(mst.begin(), mst.end());
  scanf("%d", &q);
  for (i = 1; i <= q; i++) {
    ;
    vec.clear();
    int id, num;
    scanf("%d", &num);
    for (j = 1; j <= num; j++) {
      scanf("%d", &id);
      vec.push_back(id);
    }
    sort(vec.begin(), vec.end(), cmp);
    j = 0;
    vec.push_back(0);
    while (j < vec.size() - 1) {
      query q;
      while (j + 1 < vec.size() && edges[vec[j]].w == edges[vec[j + 1]].w)
        q.vec.push_back(vec[j++]);
      q.vec.push_back(vec[j++]);
      q.id = i;
      qedge[edges[q.vec[0]].w].push_back(q);
      ;
    }
  }
  for (i = 1; i <= m; i++) {
    int w = mst[i].w;
    if (i == 4) {
      int gg;
      gg++;
    }
    if (mst[i].w != mst[i - 1].w) {
      for (j = 0; j < qedge[w].size(); j++) {
        query e = qedge[w][j];
        for (k = 0; k < del.size(); k++) edge[del[k]].clear(), vis[del[k]] = 0;
        del.clear();
        for (k = 0; k < e.vec.size(); k++) {
          Edge num = edges[e.vec[k]];
          int fau = find_fa(num.u), fav = find_fa(num.v);
          if (fau == fav) {
            ans[e.id] = 0;
            break;
          }
          edge[fau].push_back(fav);
          edge[fav].push_back(fau);
          del.push_back(fau);
          del.push_back(fav);
        }
        for (k = 0; k < del.size(); k++)
          if (!vis[del[k]] && dfs(del[k], -1)) ans[e.id] = 0;
      }
    }
    int u = mst[i].u, v = mst[i].v;
    u = find_fa(u), v = find_fa(v);
    if (u == v) continue;
    fa[u] = v;
  }
  for (i = 1; i <= q; i++) puts(ans[i] ? "YES" : "NO");
  return 0;
}
