#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 path;
vector<pi>cnt;
vi visited;
int st, C;
bool mark(int pos, int clr) {
if(cnt[pos].first == clr or cnt[pos].second == clr or cnt[pos].second != -1) return 0;
if(cnt[pos].first == -1) cnt[pos].first = clr;
else cnt[pos].second = clr;
return 1;
}
int dfs(int pos, int c=-1) {
for(auto &[adj, clr, id]: adjL[pos]) {
if(visited[id] == 1) {
path.push_back(id);
return id;
}
if(visited[id] == 2 or !mark(adj, clr)) continue;
visited[id] = 1;
int x = dfs(adj, clr);
if(x != -1) {
if(x == id) return -1;
path.push_back(id);
return 1;
}
visited[id] = 2;
}
return -1;
}
void solve() {
int n, m;
cin >> n >> m;
adjL.assign(n+1, vector<array<int,3>>());
vector<array<int,3>>vec(m);
cnt.assign(n+1, {-1,-1});
visited.assign(m+1, 0);
for(int i=0; i<m; ++i) {
int x,y,c;
cin >> x >> y >> c;
vec[i] = {x,y,c};
adjL[x].push_back({y,c,i});
}
path.clear();
for(int i=0; i<m; ++i) {
if(!visited[i] && mark(vec[i][1], vec[i][2])) {
visited[i] = 1;
st = i;
dfs(vec[i][1], vec[i][2]);
visited[i] = 2;
if(!path.empty()) {
cout << "YES" << endl << path.size() << " ";
for(int x: path) cout << x+1 << " ";
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;
}