#include <bits/stdc++.h>
using namespace std;
const int maxn = int(5e5) + 100;
struct sLink {
  int u, v, value, num;
  bool operator<(const sLink b) const { return value < b.value; }
};
int n, m, G;
int dsu[maxn], rev[maxn];
sLink Link[maxn];
bool ans[maxn];
stack<pair<int, int> > opr;
vector<pair<int, int> > que[maxn];
bool cmp(int x, int y) { return (Link[x].value < Link[y].value); }
void read() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    Link[i].num = i;
    scanf("%d%d%d", &Link[i].u, &Link[i].v, &Link[i].value);
  }
  scanf("%d", &G);
  for (int i = 1; i <= G; ++i) {
    int s;
    scanf("%d", &s);
    for (int j = 1; j <= s; ++j) {
      int nid;
      scanf("%d", &nid);
      que[Link[nid].value].push_back(make_pair(nid, i));
    }
  }
}
int dsu_find(int cur) {
  if (dsu[cur] < 0)
    return cur;
  else
    return dsu_find(dsu[cur]);
}
void join(int u, int v) {
  if (u == v) return;
  if (dsu[u] > dsu[v]) swap(u, v);
  opr.push(make_pair(v, dsu[v]));
  dsu[u] += dsu[v];
  dsu[v] = u;
}
void del() {
  pair<int, int> &cur = opr.top();
  dsu[dsu[cur.first]] -= cur.second;
  dsu[cur.first] = cur.second;
  opr.pop();
}
void change_number() {
  sort(Link + 1, Link + 1 + m);
  for (int i = 1; i <= m; ++i) rev[Link[i].num] = i;
  for (int i = 1; i <= int(5e5); ++i)
    for (auto &j : que[i]) j.first = rev[j.first];
}
void solve() {
  change_number();
  for (int i = 1; i <= n; ++i) dsu[i] = -1;
  for (int i = 1; i <= G; ++i) ans[i] = true;
  for (int i = 1; i <= m;) {
    vector<pair<int, int> > &cur = que[Link[i].value];
    int tmp = opr.size();
    for (vector<pair<int, int> >::iterator it = cur.begin(); it != cur.end();) {
      int nid = (*it).second;
      while (it != cur.end() && (*it).second == nid) {
        int fu = dsu_find(Link[(*it).first].u);
        int fv = dsu_find(Link[(*it).first].v);
        if (fu == fv) {
          ans[nid] = false;
          break;
        }
        join(fu, fv);
        ++it;
      }
      while (opr.size() != tmp) del();
      while (it != cur.end() && (*it).second == nid) ++it;
    }
    int j = i;
    while (j <= m && Link[j].value == Link[i].value) {
      join(dsu_find(Link[j].u), dsu_find(Link[j].v));
      ++j;
    }
    i = j;
  }
  for (int i = 1; i <= G; ++i)
    if (ans[i])
      printf("YES\n");
    else
      printf("NO\n");
}
int main() {
  read();
  solve();
  return 0;
}
