#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-2;
const double pi = acos(-1.0);
int dcmp(double x) {
  if (fabs(x) <= eps) return 0;
  return (x > 0) ? 1 : -1;
};
void umax(long long &a, long long b) { a = max(a, b); }
void umin(long long &a, long long b) { a = min(a, b); }
void file() {
  freopen("out.txt", "r", stdin);
  freopen("1.txt", "w", stdout);
}
namespace solver {
int n, m;
int ans[550000];
struct A {
  vector<int> G;
  map<int, vector<int>> mp;
};
A G[550000];
struct E {
  int u, v, w;
  bool operator<(const E &b) const { return w < b.w; }
} edge[1100000], pe[1100000];
vector<int> ask[550000];
namespace DSU {
int fa[550000], rk[550000];
stack<pair<int *, int>> stk;
void init() {
  for (int i = 0; i < 550000; i++) fa[i] = i, rk[i] = 1;
}
int find(int x) { return x == fa[x] ? x : find(fa[x]); }
void merge(int u, int v, int on) {
  int f1 = find(u), f2 = find(v);
  if (rk[f1] > rk[f2]) swap(f1, f2);
  if (on) stk.push({&fa[f1], fa[f1]});
  fa[f1] = f2;
  if (on) stk.push({&rk[f2], rk[f2]});
  rk[f2] += rk[f1];
}
void goback() {
  while (!stk.empty()) {
    (*stk.top().first) = stk.top().second;
    stk.pop();
  }
}
}  // namespace DSU
void solve() {
  for (int i = 0; i < 550000; i++) ans[i] = 1;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++)
    scanf("%d%d%d", &edge[i].u, &edge[i].v, &edge[i].w), pe[i] = edge[i];
  sort(edge + 1, edge + 1 + m);
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int k;
    scanf("%d", &k);
    while (k--) {
      int v;
      scanf("%d", &v);
      G[pe[v].w].G.push_back(i);
      G[pe[v].w].mp[i].push_back(v);
    }
  }
  DSU::init();
  int p = 1;
  for (int i = 1; i <= 500000; i++) {
    if (G[i].G.empty()) continue;
    while (edge[p].w < i) {
      int u = edge[p].u, v = edge[p].v;
      int f1 = DSU::find(u), f2 = DSU::find(v);
      if (f1 != f2) DSU::merge(u, v, 0);
      p++;
      if (p > m) break;
    }
    A x = G[i];
    sort(x.G.begin(), x.G.end());
    x.G.erase(unique(x.G.begin(), x.G.end()), x.G.end());
    for (auto t : x.G) {
      vector<int> V = x.mp[t];
      for (auto tt : V) {
        int u = pe[tt].u, v = pe[tt].v;
        int f1 = DSU::find(u), f2 = DSU::find(v);
        if (f1 == f2)
          ans[t] = 0;
        else
          DSU::merge(u, v, 1);
      }
      DSU::goback();
    }
  }
  for (int i = 1; i <= q; i++) {
    puts(ans[i] ? "YES" : "NO");
  }
}
}  // namespace solver
int main() {
  solver::solve();
  return 0;
}
