#include <bits/stdc++.h>
using namespace std;
const double pi =
    3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int MR = 5e5 + 10;
int p[MR], r[MR];
void makeset(int x, int *p, int *r) {
  p[x] = x;
  r[x] = 0;
}
void unionset(int x, int y, int *p, int *r) {
  if (r[x] > r[y])
    p[y] = x;
  else {
    p[x] = y;
    if (r[x] == r[y]) r[y]++;
  }
}
int findset(int x, int *p) {
  if (p[x] != x) p[x] = findset(p[x], p);
  return p[x];
}
int akt, spr[MR];
int pM[MR], rM[MR];
void unionset(int x, int y) {
  if (spr[x] != akt) {
    spr[x] = akt;
    pM[x] = x;
    rM[x] = 0;
  }
  if (spr[y] != akt) {
    spr[y] = akt;
    pM[y] = y;
    rM[y] = 0;
  }
  if (rM[x] > rM[y])
    pM[y] = x;
  else {
    pM[x] = y;
    if (rM[x] == rM[y]) rM[y]++;
  }
}
int findset(int x) {
  if (spr[x] != akt) {
    spr[x] = akt;
    pM[x] = x;
    rM[x] = 0;
  }
  if (pM[x] != x) pM[x] = findset(pM[x]);
  return pM[x];
}
pair<pair<int, int>, pair<int, int>> t[MR], t1[MR], tab[MR];
bool ok[MR];
vector<int> g[MR];
int CC[MR], ilec;
void dfs(int nr) {
  CC[nr] = ilec;
  for (int i : g[nr])
    if (!CC[i]) dfs(i);
}
map<pair<int, int>, vector<int>> pom;
int sprCC[MR];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (n); ++i) makeset(i, p, r);
  for (int i = 0; i < (m); ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--;
    v--;
    t1[i] = t[i] = make_pair(make_pair(w, i), make_pair(u, v));
  }
  sort(t, t + m);
  for (int i = 0; i < m;) {
    int j = i + 1;
    while (j < m && t[j].first.first == t[i].first.first) j++;
    for (int k = (i); k < (j); ++k)
      if (findset(t[k].second.first, p) != findset(t[k].second.second, p)) {
        ok[t[k].first.second] = 1;
        pair<int, int> pr = make_pair(findset(t[k].second.first, p),
                                      findset(t[k].second.second, p));
        if (!pom[pr].empty()) {
          g[t[k].first.second].push_back(pom[pr].back());
          g[pom[pr].back()].push_back(t[k].first.second);
        }
        pom[pr].push_back(t[k].first.second);
      }
    for (int k = (i); k < (j); ++k)
      if (findset(t[k].second.first, p) != findset(t[k].second.second, p))
        unionset(findset(t[k].second.first, p), findset(t[k].second.second, p),
                 p, r);
    i = j;
  }
  for (int i = 0; i < (m); ++i)
    if (!CC[i]) {
      ilec++;
      dfs(i);
    }
  int q;
  scanf("%d", &q);
  for (int c = 0; c < (q); ++c) {
    akt++;
    int k;
    scanf("%d", &k);
    bool res = 1;
    for (int i = 0; i < (k); ++i) {
      int ind;
      scanf("%d", &ind);
      ind--;
      res = (res && ok[ind]);
      if (sprCC[CC[ind]] == akt) res = 0;
      sprCC[CC[ind]] = akt;
      tab[i] = t1[ind];
    }
    if (res) {
      sort(tab, tab + k);
      for (int i = 0; i < (k); ++i)
        if (findset(tab[i].second.first) != findset(tab[i].second.second))
          unionset(findset(tab[i].second.first), findset(tab[i].second.second));
        else {
          res = 0;
          break;
        }
    }
    if (res)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
