#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
inline int read() {
  register int x;
  register char c, op = 0;
  while (c = getchar(), c < '0' || c > '9')
    if (c == '-') op = !op;
  x = c ^ 48;
  while (c = getchar(), c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48);
  return op ? -x : x;
}
int n, m, q;
struct edge {
  int x, y, val, id;
  int tx, ty;
} e[N];
int p[N];
bool cmp1(edge a, edge b) { return a.val < b.val; }
bool cmp2(edge a, edge b) { return a.id < b.id; }
int find(int x) {
  if (x == p[x]) return x;
  return p[x] = find(p[x]);
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 1; i <= m; i++)
    e[i].x = read(), e[i].y = read(), e[i].val = read(), e[i].id = i;
  sort(e + 1, e + m + 1, cmp1);
  for (int i = 1; i <= m; i++) {
    int j = i - 1;
    while (j + 1 <= m && e[j + 1].val == e[i].val) {
      e[j + 1].tx = find(e[j + 1].x);
      e[j + 1].ty = find(e[j + 1].y);
      j++;
    }
    for (int k = i; k <= j; k++) {
      p[find(e[k].x)] = find(e[k].y);
    }
    i = j;
  }
  q = read();
  sort(e + 1, e + m + 1, cmp2);
  for (int i = 1; i <= n; i++) p[i] = i;
  while (q--) {
    int k = read();
    vector<edge> a;
    for (int i = 1; i <= k; i++) {
      int x = read();
      a.push_back({e[x].tx, e[x].ty, e[x].val});
    }
    sort(a.begin(), a.end(), cmp1);
    bool flag = true;
    for (int i = 0, sz = a.size() - 1; flag && i <= sz; i++) {
      int j = i - 1;
      while (j + 1 <= sz && a[j + 1].val == a[i].val) {
        j++;
        if (find(a[j].x) == find(a[j].y)) {
          flag = false;
          break;
        }
        p[find(a[j].x)] = find(a[j].y);
      }
      for (int k = i; k <= j; k++) p[a[k].x] = a[k].x, p[a[k].y] = a[k].y;
      i = j;
    }
    if (flag)
      puts("YES");
    else
      puts("NO");
  }
}
