#include <bits/stdc++.h>
using namespace std;
char buf[1 << 21], *p1 = buf, *p2 = buf;
inline int qread() {
  register char c =
      (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
           ? EOF
           : *p1++);
  register int x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++);
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - 48;
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++);
  }
  return x * f;
}
inline int Abs(const int& x) { return (x > 0 ? x : -x); }
inline int Max(const int& x, const int& y) { return (x > y ? x : y); }
inline int Min(const int& x, const int& y) { return (x < y ? x : y); }
struct Edge {
  int u, v, w;
  inline bool operator<(const Edge& b) const { return w < b.w; }
};
int n, m, q, seq[500005];
bool ans[500005];
Edge e[500005], e2[500005];
struct Query {
  vector<int> idx;
  int qid;
  Query() {}
  Query(int qid) : qid(qid) {}
};
vector<Query> vc[500005];
struct DSU {
  int f[500005], siz[500005];
  stack<pair<int, int> > stk;
  inline void Init(int n) {
    for (int i = 1; i <= n; i++) {
      f[i] = i;
      siz[i] = 1;
    }
  }
  inline int GetRoot(int v) {
    if (v == f[v]) return v;
    return GetRoot(f[v]);
  }
  inline bool Merge(int x, int y) {
    int u = GetRoot(x), v = GetRoot(y);
    if (u != v) {
      if (siz[u] < siz[v]) swap(u, v);
      stk.push(make_pair(v, f[v]));
      f[v] = u;
      stk.push(make_pair(u + n, siz[u]));
      siz[u] += siz[v];
      return 1;
    }
    return 0;
  }
  inline void Rollback() {
    pair<int, int> cur = stk.top();
    if (cur.first <= n)
      f[cur.first] = cur.second;
    else
      siz[cur.first - n] = cur.second;
    stk.pop();
  }
};
DSU dsu;
inline bool cmp1(int i, int j) { return e[i].w < e[j].w; }
inline void Read() {
  n = qread();
  m = qread();
  for (int i = 1; i <= m; i++) {
    e[i].u = qread();
    e[i].v = qread();
    e[i].w = qread();
  }
  memcpy(e2, e, sizeof(e2));
  sort(e2 + 1, e2 + m + 1);
  q = qread();
  for (int i = 1; i <= q; i++) {
    int k = qread();
    for (int j = 1; j <= k; j++) seq[j] = qread();
    sort(seq + 1, seq + k + 1, cmp1);
    for (int j = 1; j <= k; j++) {
      if (e[seq[j]].w != e[seq[j - 1]].w) vc[e[seq[j]].w].push_back(Query(i));
      vc[e[seq[j]].w].back().idx.push_back(seq[j]);
    }
    ans[i] = 1;
  }
}
inline void Solve() {
  dsu.Init(n);
  int epnt = 1;
  for (int i = 1; i <= 500000; i++) {
    int siz = vc[i].size();
    for (int j = 0; j < siz; j++) {
      int ssiz = vc[i][j].idx.size();
      int curid = dsu.stk.size();
      for (int k = 0; k < ssiz; k++) {
        if (!dsu.Merge(e[vc[i][j].idx[k]].u, e[vc[i][j].idx[k]].v)) {
          ans[vc[i][j].qid] = 0;
          break;
        }
      }
      while (dsu.stk.size() != curid) dsu.Rollback();
    }
    while (e2[epnt].w <= i && epnt <= m) {
      dsu.Merge(e2[epnt].u, e2[epnt].v);
      epnt++;
    }
  }
  for (int i = 1; i <= q; i++) puts((ans[i] ? "YES" : "NO"));
}
int main() {
  Read();
  Solve();
  return 0;
}
