#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
int n, m, q, cnt = 0;
int x[N], y[N], w[N];
int head[N], fa[N], pa[N], rk[N];
bool mark[N];
vector<int> e[N];
vector<pair<int, int> > que[N];
inline int getFa(int v) { return fa[v] == v ? v : fa[v] = getFa(fa[v]); }
inline int get(int v) {
  if (rk[v] != cnt) rk[v] = cnt, pa[v] = fa[v];
  return pa[v] == v ? v : pa[v] = get(pa[v]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (m); i++) {
    scanf("%d%d%d", &x[i], &y[i], &w[i]);
    e[w[i]].push_back(i);
  }
  scanf("%d", &q);
  for (int i = (1); i <= (q); i++) {
    int K;
    scanf("%d", &K);
    while (K--) {
      int t;
      scanf("%d", &t);
      que[w[t]].push_back(make_pair(i, t));
    }
  }
  for (int i = (1); i <= (n); i++) fa[i] = i;
  for (int i = (1); i <= (500000); i++) {
    sort(que[i].begin(), que[i].end());
    for (int j = 0; j < que[i].size(); j++) {
      getFa(x[que[i][j].second]);
      getFa(y[que[i][j].second]);
    }
    for (int j = 0; j < que[i].size(); j++) {
      if (j == 0 || que[i][j].first != que[i][j - 1].first) cnt++;
      int xx = x[que[i][j].second], yy = y[que[i][j].second];
      if (get(xx) == get(yy)) mark[que[i][j].first] = 1;
      pa[get(xx)] = get(yy);
    }
    for (auto j : e[i]) {
      int xx = x[j], yy = y[j];
      fa[getFa(xx)] = getFa(yy);
    }
  }
  for (int i = (1); i <= (q); i++)
    if (mark[i])
      puts("NO");
    else
      puts("YES");
  return 0;
}
