#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005, MAXM = 500005;
int N, M, Q;
struct Edge {
  int u, v, w;
} e[MAXM];
int K, edgeId[MAXM], cntQuery = 0;
struct Query {
  int K, queryId;
  vector<int> edgeId;
} q[MAXM];
bool operator<(const Edge &A, const Edge &B) { return A.w < B.w; }
bool cmp(int x, int y) { return e[x].w < e[y].w; }
bool operator<(const Query &A, const Query &B) {
  return e[A.edgeId[0]].w < e[B.edgeId[0]].w;
}
int f[MAXN];
bool ans[MAXM], visited[MAXN];
vector<int> eList[MAXN];
int findF(int x) { return f[x] < 0 ? x : f[x] = findF(f[x]); }
void Union(int x, int y) {
  int fx = findF(x), fy = findF(y);
  if (fx == fy) return;
  f[fx] = fy;
}
bool DFS(int x, int father) {
  visited[x] = true;
  int s = eList[x].size();
  for (int i = 0; i < s; ++i) {
    int y = eList[x][i];
    if (y == father) continue;
    if (visited[y]) return true;
    if (DFS(y, x)) return true;
  }
  return false;
}
bool check(int ptrQuery) {
  for (int i = 0; i < q[ptrQuery].K; ++i) {
    int x = findF(e[q[ptrQuery].edgeId[i]].u),
        y = findF(e[q[ptrQuery].edgeId[i]].v);
    eList[x].push_back(y);
    eList[y].push_back(x);
    visited[x] = visited[y] = false;
  }
  bool ans = false;
  for (int i = 0; i < q[ptrQuery].K && !ans; ++i) {
    int x = findF(e[q[ptrQuery].edgeId[i]].u);
    if (!visited[x]) ans |= DFS(x, -1);
  }
  for (int i = 0; i < q[ptrQuery].K; ++i) {
    eList[findF(e[q[ptrQuery].edgeId[i]].u)].clear();
    eList[findF(e[q[ptrQuery].edgeId[i]].v)].clear();
  }
  return ans;
}
void solve() {
  for (int i = 1; i <= N; ++i) f[i] = -1;
  for (int i = 1; i <= M; ++i) edgeId[i] = i;
  for (int i = 1; i <= Q; ++i) ans[i] = true;
  sort(edgeId + 1, edgeId + M + 1, cmp);
  int ptrEdge = 1, ptrQuery = 1;
  while (ptrQuery <= cntQuery) {
    while (e[edgeId[ptrEdge]].w < e[q[ptrQuery].edgeId[0]].w)
      Union(e[edgeId[ptrEdge]].u, e[edgeId[ptrEdge]].v), ++ptrEdge;
    if (check(ptrQuery)) ans[q[ptrQuery].queryId] = false;
    ++ptrQuery;
  }
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= M; ++i) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  scanf("%d", &Q);
  for (int i = 1; i <= Q; ++i) {
    scanf("%d", &K);
    for (int j = 1; j <= K; ++j) scanf("%d", edgeId + j);
    sort(edgeId + 1, edgeId + K + 1, cmp);
    int j = 1;
    q[++cntQuery].K = 0, q[cntQuery].queryId = i;
    while (j <= K) {
      if (j > 1 && e[edgeId[j]].w != e[edgeId[j - 1]].w)
        q[++cntQuery].K = 0, q[cntQuery].queryId = i;
      ++q[cntQuery].K, q[cntQuery].edgeId.push_back(edgeId[j]);
      ++j;
    }
  }
  sort(q + 1, q + cntQuery + 1);
  solve();
  for (int i = 1; i <= Q; ++i) printf("%s\n", ans[i] ? "YES" : "NO");
  return 0;
}
