#include <bits/stdc++.h>
using namespace std;
int n, m, q;
struct Edge {
  int x, y, w, idx;
  bool operator<(const Edge& ot) const { return w < ot.w; }
} E[500002], inE[500002];
struct Nod {
  int f, sz;
} v[500002];
struct Change {
  Nod* address;
  Nod oldValue;
};
stack<Change> changes;
struct Query {
  int id;
  vector<int> e;
} Q[500002];
vector<int> V[500002];
bool ans[500002];
bool cmp(const int a, const int b) { return E[a].w < E[b].w; }
int root(int x) {
  if (v[x].f == 0)
    return x;
  else {
    changes.push(Change{&v[x], v[x]});
    return v[x].f = root(v[x].f);
  }
}
void Union(int x, int y) {
  int rx = root(x), ry = root(y);
  if (rx != ry) {
    changes.push(Change{&v[rx], v[rx]});
    changes.push(Change{&v[ry], v[ry]});
    if (v[rx].sz < v[ry].sz) {
      v[rx].f = ry;
      v[ry].sz += v[rx].sz;
    } else {
      v[ry].f = rx;
      v[rx].sz += v[ry].sz;
    }
  }
}
void undo() {
  while (!changes.empty()) {
    Change x = changes.top();
    *x.address = x.oldValue;
    changes.pop();
  }
}
void readQuery(int i) {
  int l;
  scanf("%d", &l);
  Q[i].e.resize(l);
  for (int j = 0; j < l; ++j) scanf("%d", &Q[i].e[j]);
  sort(Q[i].e.begin(), Q[i].e.end(), cmp);
  V[E[Q[i].e[0]].w].push_back(i);
  for (int j = 1; j < l; ++j)
    if (E[Q[i].e[j]].w != E[Q[i].e[j - 1]].w) V[E[Q[i].e[j]].w].push_back(i);
}
void solveQueries() {
  int j = 1;
  sort(E + 1, E + m + 1);
  for (int i = 1; i <= m; ++i)
    if (E[i].w != E[i - 1].w) {
      for (; j < i; ++j) Union(E[j].x, E[j].y);
      while (!changes.empty()) changes.pop();
      for (int query : V[E[i].w])
        if (ans[query]) {
          int l = Q[query].e.size();
          for (int idx = Q[query].id;
               idx < l && inE[Q[query].e[idx]].w == E[i].w;
               ++idx, ++Q[query].id) {
            int x = inE[Q[query].e[idx]].x, y = inE[Q[query].e[idx]].y;
            if (root(x) == root(y)) {
              ans[query] = 0;
              break;
            }
            Union(x, y);
          }
          undo();
        }
    }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &E[i].x, &E[i].y, &E[i].w);
    E[i].idx = i;
    inE[i] = E[i];
  }
  scanf("%d", &q);
  for (int i = 1; i <= n; ++i) v[i].sz = 1;
  for (int i = 1; i <= q; ++i) {
    ans[i] = 1;
    readQuery(i);
  }
  solveQueries();
  for (int i = 1; i <= q; ++i)
    if (ans[i])
      printf("YES\n");
    else
      printf("NO\n");
  return 0;
}
