#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using pi = pair<int,int>;
const int MAX = 1e9;
vector<vector<array<int,3>>>adjL;
vi cnt, path;
vector<bool>visited;
int st, C;
bool dfs(int pos, int c=-1) {
if(pos == st && c != C) return 1;
for(auto &[adj, clr, id]: adjL[pos]) {
if(cnt[adj] == MAX or clr == c or visited[id]) continue;
visited[id] = 1;
if(cnt[adj] == -1) cnt[adj] = c;
else cnt[adj] = MAX;
if(dfs(adj, clr)) {
path.push_back(id);
return 1;
}
}
return 0;
}
void solve() {
int n, m;
cin >> n >> m;
adjL.assign(n+1, vector<array<int,3>>());
vector<array<int,4>>vec(m);
for(int i=0; i<m; ++i) {
int x,y,c;
cin >> x >> y >> c;
vec[i] = {x,y,c,i+1};
adjL[x].push_back({y,c,i+1});
}
path.clear();
for(int i=0; i<m; ++i) {
st = vec[i][0];
C = vec[i][2];
cnt.assign(n+1, -1);
visited.assign(m+1, 0);
visited[vec[i][3]] = 1;
dfs(vec[i][1], C);
if(!path.empty()) {
path.push_back(vec[i][3]);
reverse(path.begin(), path.end());
cout << "YES" << endl << path.size() << " ";
for(int x: path) cout << x << " ";
cout << endl;
return;
}
}
cout << "NO" << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int tc;
cin >> tc;
while(tc--) solve();
return 0;
}