#include <bits/stdc++.h>
using namespace std;
int F[500005];
int f[500005];
vector<int> ud[500005];
vector<int> V[500005];
int gf(int A) { return F[A] == A ? A : (F[A] = gf(F[A])); }
struct Node {
  int a, b, c;
} N[500005];
bool operator<(Node A, Node B) { return A.c < B.c; }
int n, m, q, tot = 0;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) F[i] = i;
  for (int i = 1; i <= m; ++i)
    scanf("%d%d%d", &N[i].a, &N[i].b, &N[i].c), V[N[i].c].push_back(i);
  for (int i = 1; i <= 500001; ++i) {
    for (unsigned int j = 0; j < V[i].size(); ++j) {
      N[V[i][j]].a = gf(N[V[i][j]].a);
      N[V[i][j]].b = gf(N[V[i][j]].b);
    }
    for (unsigned int j = 0; j < V[i].size(); ++j)
      F[gf(N[V[i][j]].a)] = gf(N[V[i][j]].b);
  }
  scanf("%d", &q);
  while (q--) {
    int k;
    scanf("%d", &k);
    set<int> S;
    set<int>::iterator it;
    for (int i = 1; i <= k; ++i) scanf("%d", f + i), ud[N[f[i]].c].clear();
    for (int i = 1; i <= k; ++i)
      S.insert(N[f[i]].c), ud[N[f[i]].c].push_back(f[i]);
    int ok = 1;
    for (it = S.begin(); it != S.end(); ++it) {
      int i = *it;
      for (unsigned int j = 0; j < ud[i].size(); ++j) {
        F[N[ud[i][j]].a] = N[ud[i][j]].a;
        F[N[ud[i][j]].b] = N[ud[i][j]].b;
      }
      for (unsigned int j = 0; j < ud[i].size(); ++j) {
        if (gf(N[ud[i][j]].a) == gf(N[ud[i][j]].b)) ok = 0;
        F[gf(N[ud[i][j]].a)] = gf(N[ud[i][j]].b);
      }
    }
    puts(ok ? "YES" : "NO");
  }
  return 0;
}
