#include <bits/stdc++.h>
using namespace std;
int n, m, q;
struct node {
  int start, endd, weightt;
  bool operator<(const node &a) const { return weightt < a.weightt; }
} pic[500100];
struct question {
  int id, start, endd, wei;
  bool operator<(const question &a) const {
    if (wei == a.wei) return id < a.id;
    return wei < a.wei;
  }
} qes[500100];
int pre[500100];
int pa[500100];
int mark[500100];
int ans[500100];
int find1(int x) {
  if (x == pre[x])
    return x;
  else
    return pre[x] = find1(pre[x]);
}
int find2(int x, int tag) {
  if (mark[x] != tag) {
    pa[x] = pre[x];
    mark[x] = tag;
  }
  if (x == pa[x])
    return x;
  else
    return pa[x] = find2(pa[x], tag);
}
int main() {
  scanf("%d %d", &n, &m);
  int i, j;
  for (i = 1; i <= m; i++) {
    scanf("%d %d %d", &pic[i].start, &pic[i].endd, &pic[i].weightt);
  }
  scanf("%d", &q);
  int tot = 0;
  int x, y;
  for (i = 1; i <= q; i++) {
    scanf("%d", &x);
    for (j = 1; j <= x; j++) {
      scanf("%d", &y);
      qes[++tot].id = i;
      qes[tot].start = pic[y].start;
      qes[tot].endd = pic[y].endd;
      qes[tot].wei = pic[y].weightt;
    }
  }
  sort(pic + 1, pic + 1 + m);
  sort(qes + 1, qes + 1 + tot);
  for (i = 1; i <= n; i++) {
    pre[i] = i;
    pa[i] = i;
  }
  int pos1 = 1, pos2 = 1;
  int tag = 0;
  for (i = 1; i <= tot; i = pos2) {
    while (pic[pos1].weightt < qes[i].wei && pos1 <= m) {
      int a = find1(pic[pos1].start);
      int b = find1(pic[pos1].endd);
      if (a != b) pre[b] = a;
      pos1++;
    }
    while (qes[pos2].wei == qes[i].wei && pos2 <= tot) {
      if (pos2 == i || qes[pos2].id != qes[pos2 - 1].id) tag++;
      int a = find2(qes[pos2].start, tag);
      int b = find2(qes[pos2].endd, tag);
      if (a == b)
        ans[qes[pos2].id] = 1;
      else
        pa[b] = a;
      pos2++;
    }
  }
  for (i = 1; i <= q; i++) {
    if (ans[i])
      printf("NO\n");
    else
      printf("YES\n");
  }
  return 0;
}
