#include <bits/stdc++.h>
int n, m, Q, num, cnt;
int f[(int)(5e5 + 10)], prt[(int)(5e5 + 10)], now[(int)(5e5 + 10)];
struct qwq {
  int from, to, w;
} a[(int)(5e5 + 10)], b[(int)(5e5 + 10)];
int vis[(int)(5e5 + 10)];
std::vector<std::pair<int, int> > vec[(int)(5e5 + 10)];
void Read(int &x) {
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c <= '9' && c >= '0') x = (x << 1) + (x << 3) + c - '0', c = getchar();
}
bool Cmp(const qwq &a, const qwq &b) { return a.w < b.w; }
int Find(int x) {
  if (x != prt[x]) prt[x] = Find(prt[x]);
  return prt[x];
}
int FinD(int x) {
  if (now[x] != cnt) now[x] = cnt, f[x] = prt[x];
  if (x != f[x]) f[x] = FinD(f[x]);
  return f[x];
}
int main() {
  Read(n), Read(m);
  for (int i = 1; i <= n; ++i) prt[i] = i;
  for (int i = 1; i <= m; ++i)
    Read(a[i].from), Read(a[i].to), Read(a[i].w), b[i] = a[i];
  Read(Q);
  for (int i = 1, x; i <= Q; ++i) {
    Read(num);
    while (num--) Read(x), vec[a[x].w].push_back(std::make_pair(i, x));
  }
  std::sort(a + 1, a + 1 + m, Cmp);
  for (int i = 1; i <= m; ++i) {
    int L = i, R = i, v = a[i].w;
    while (a[R + 1].w == a[L].w && R + 1 <= m) R++;
    std::sort(vec[v].begin(), vec[v].end());
    for (int j = 0; j < vec[v].size(); ++j) {
      if (j == 0 || vec[v][j].first != vec[v][j - 1].first) cnt++;
      int x = b[vec[v][j].second].from, y = b[vec[v][j].second].to;
      int fx = FinD(x), fy = FinD(y);
      if (fx == fy) vis[vec[v][j].first] = 1;
      f[fy] = fx;
    }
    for (int j = L; j <= R; ++j) {
      int fx = Find(a[j].from), fy = Find(a[j].to);
      prt[fy] = fx;
    }
    i = R;
  }
  for (int i = 1; i <= Q; ++i)
    if (vis[i])
      printf("NO\n");
    else
      printf("YES\n");
}
