#include <bits/stdc++.h>
using namespace std;
const int N = 500500;
bool Ans[N];
int Weight[N];
pair<int, int> Edges1[N];
vector<int> Edges2[N];
vector<pair<int, vector<int> > > Query[N];
int P[N];
stack<pair<int, int> > Was;
void Clear() {
  while (!Was.empty()) Was.pop();
}
void Restore() {
  while (!Was.empty()) {
    int x = Was.top().first;
    int p = Was.top().second;
    P[x] = p;
    Was.pop();
  }
}
int F(int x) {
  if (x == P[x]) return x;
  Was.push(make_pair(x, P[x]));
  return P[x] = F(P[x]);
}
bool Un(int x, int y) {
  if ((x = F(x)) == (y = F(y))) return false;
  if (rand() & 1) swap(x, y);
  Was.push(make_pair(x, P[x]));
  P[x] = y;
  return true;
}
int main() {
  srand(time(0));
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y, w;
    scanf("%d%d%d", &x, &y, &w);
    Weight[i] = w;
    Edges1[i] = pair<int, int>(x, y);
    Edges2[w].push_back(i);
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      int Idx;
      scanf("%d", &Idx);
      int w = Weight[Idx];
      if (Query[w].empty() || Query[w].back().first != i)
        Query[w].push_back(make_pair(i, vector<int>()));
      Query[w].back().second.push_back(Idx);
    }
  }
  for (int i = 1; i <= q; i++) Ans[i] = true;
  for (int i = 1; i <= n; i++) P[i] = i;
  for (int w = 1; w < N; w++) {
    for (int i = 0; i < Query[w].size(); i++) {
      int Idx = Query[w][i].first;
      vector<int>& v = Query[w][i].second;
      for (int j : v) {
        int x = Edges1[j].first;
        int y = Edges1[j].second;
        Ans[Idx] &= Un(x, y);
      }
      Restore();
    }
    for (int i : Edges2[w]) {
      int x = Edges1[i].first;
      int y = Edges1[i].second;
      Un(x, y);
    }
    Clear();
  }
  for (int i = 1; i <= q; i++) puts(Ans[i] ? "YES" : "NO");
}
