#include <bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
using vpi = vector<pi>;
using vvpi = vector<vpi>;
using vi = vector<int>;
using vvi = vector<vi>;
/*
we want to create a new graph of nodes {u,p} = {node, attraction we came from} that includes {u,ø}
*/
void solve() {
int n, m; cin >> n >> m;
map<pi, vpi> G; vvi R(n);
vi x(m), y(m), c(m);
for (int i = 0; i < m; i++) {
cin >> x[i] >> y[i] >> c[i];
x[i]--; y[i]--; c[i]--;
G[{x[i], -1}].push_back({i, c[i]});
R[y[i]].push_back(c[i]);
}
for (int i = 0; i < n; i++) {
for (auto w : R[i]) {
for (auto [v,w2] : G[{i,-1}]) {
if (w != w2) G[{i, w}].push_back({v,w2});
}
}
}
map<pi, int> par;
map<pi, pi> par2;
set<pi> active;
auto dfs = [&](auto &&self, pi u) {
active.insert(u);
for (auto e : G[u]) {
pi v = {y[e.first], e.second};
if (active.count(v)) {
cout << "YES\n";
vector<int> out;
auto c1 = u;
while (c1 != v) {
out.push_back(par[c1]);
c1 = par2[c1];
}
reverse(out.begin(), out.end());
out.push_back(e.first);
cout << out.size() << "\n";
for (auto g : out) cout << g+1 << " "; cout << "\n";
return true;
} else if (par.count(v)) {
continue;
}
par[v] = e.first;
par2[v] = u;
if (self(self, v)) return true;
}
active.erase(u);
return false;
};
for (auto &[f,_] : G) {
if (par.count(f)) continue;
par[f] = -1; par2[f] = {-1,-1};
if (dfs(dfs, f)) return;
}
cout << "NO\n";
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t; cin >> t;
while (t--) solve();
return 0;
}