#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int u, v, w;
} e[500005];
struct Ask {
  int gg;
  vector<int> v;
} temp;
int root[500005], copys[500005];
int nowask[500005];
bool ans[500005];
queue<int> returns;
vector<Ask> asks[500005];
vector<int> vec[500005];
bool cmp(int x1, int x2) {
  if (e[x1].w == e[x2].w)
    return x1 < x2;
  else
    return e[x1].w < e[x2].w;
}
int findr(int x) {
  if (x == root[x])
    return x;
  else
    return root[x] = findr(root[x]);
}
int askr(int x) {
  if (x != root[x]) {
    if (!copys[x]) {
      copys[x] = root[x];
      returns.push(x);
    }
    root[x] = askr(root[x]);
  }
  return root[x];
}
int main() {
  int n, m, q, now, w, x, y;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) root[i] = i;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
    vec[e[i].w].push_back(i);
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &now);
    for (int j = 0; j < now; j++) scanf("%d", &nowask[j]);
    sort(nowask, nowask + now);
    w = e[nowask[0]].w;
    temp.gg = i;
    (temp.v).clear();
    for (int j = 0; j < now; j++) {
      if (w != e[nowask[j]].w) {
        asks[w].push_back(temp);
        w = e[nowask[j]].w;
        (temp.v).clear();
      }
      (temp.v).push_back(nowask[j]);
    }
    asks[w].push_back(temp);
  }
  for (int i = 1; i <= 500000; i++) {
    for (int j = 0; j < asks[i].size(); j++) {
      for (int k = 0; k < (asks[i][j].v).size(); k++) {
        x = askr(e[asks[i][j].v[k]].u);
        y = askr(e[asks[i][j].v[k]].v);
        if (x != y) {
          if (!copys[x]) {
            copys[x] = root[x];
            returns.push(x);
          }
          root[x] = y;
        } else {
          ans[asks[i][j].gg] = 1;
          break;
        }
      }
      while (!returns.empty()) {
        now = returns.front();
        returns.pop();
        root[now] = copys[now];
        copys[now] = 0;
      }
    }
    for (int j = 0; j < vec[i].size(); j++) {
      x = findr(e[vec[i][j]].u);
      y = findr(e[vec[i][j]].v);
      if (x != y) root[x] = y;
    }
  }
  for (int i = 1; i <= q; i++) {
    if (ans[i])
      printf("NO\n");
    else
      printf("YES\n");
  }
  return 0;
}
