#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int maxn=1e6+10;
vector<pair<int,pii>>v[maxn];
int marc[maxn][2], foi_id[maxn][2], agr[maxn], foi_cor[maxn][2];
stack<pii>st;
vector<int>ans;
void get(int x, int t, int extra){
if(ans.size()) return;
ans.push_back(extra);
// cerr << "LETS GO!!!\n";
stack<pii>aux=st;
while(aux.size()){
ans.push_back(foi_id[aux.top().fi][aux.top().se]);
if(aux.top().fi==x&&aux.top().se==t) break;
aux.pop();
}
reverse(ans.begin(),ans.end());
}
void output(){
// stack<pii>aux=st;
// vector<pii>z;
// while(aux.size()){
// z.push_back(aux.top()); aux.pop();
// }
// reverse(z.begin(),z.end());
// cerr << "stack: ";
// for(pii p : z) cout << '(' << p.fi << ',' << p.se << ") ";
// cerr << '\n';
}
void dfs(int u, int c){
for(pair<int,pii> p : v[u]){
int viz=p.se.fi, cor=p.se.se, id=p.fi;
if(c==cor) continue;
if(agr[viz]){
// output();
// cerr << "! " << u << ' ' << viz << ' ' << cor << ' ' << foi_cor[viz][0] << '\n';
// cerr << "!! " << u << ' ' << viz << ' ' << cor << ' ' << foi_cor[viz][1] << '\n';
if(foi_cor[viz][0]!=cor) get(viz,0,id);
else if(foi_cor[viz][1]!=cor&&foi_cor[viz][1]!=0) get(viz,1,id);
}
if((marc[viz][0]&&marc[viz][1])||marc[viz][0]==cor||marc[viz][1]==cor) continue;
int e=agr[u];
if(marc[viz][0]){
foi_cor[u][e]=marc[viz][1]=cor;
foi_id[u][e]=id; agr[u]++; st.push({u,e});
dfs(viz,cor);
foi_cor[u][e]=foi_id[u][e]=0; agr[u]--; st.pop();
}else{
foi_cor[u][e]=marc[viz][0]=cor;
foi_id[u][e]=id; agr[u]++; st.push({u,e});
dfs(viz,cor);
foi_cor[u][e]=foi_id[u][e]=0; agr[u]--; st.pop();
}
}
}
void solve(){
ans.clear();
int n, m; cin >> n >> m;
for(int i=1;i<=n;i++) v[i].clear();
vector<pair<int,pii>>aresta;
for(int i=1;i<=m;i++){
int a, b, c; cin >> a >> b >> c;
v[a].push_back({i,{b,c}});
}
for(int j=1;j<=n;j++) marc[j][0]=marc[j][1]=0;
for(int i=1;i<=n;i++){
// for(int j=1;j<=n;j++) marc[j][0]=marc[j][1]=0;
if(marc[i][0]) continue;
dfs(i,-1);
if(ans.size()){
cout << "YES\n";
cout << ans.size() << ' ';
for(int x : ans) cout << x << ' ';
cout << '\n';
return;
}
}
cout << "NO\n";
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int t; cin >> t;
while(t--) solve();
}