#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e6+10;
vector<int>graph[MAXN], colour[MAXN], idx[MAXN], marc(MAXN), out[MAXN];
stack<int>edges;
vector<pair<pair<int, int>, int>>e;
bool ok;
void ans(int find_x, int find_c){
vector<int>resp;
while(true){
int at=edges.top();
edges.pop();
resp.push_back(at);
if(find_x==e[at].first.first and find_c==e[at].second){
cout<<"YES"<<endl;
for(int k=resp.size()-1;k>=0;k--){
cout<<resp[k]<<' ';
}
cout<<endl;
return;
}
}
}
void dfs(int x, int c){
marc[x]++;
if(marc[x]==3){
return;
}
for(int k=0;k<graph[x].size();k++){
int neighbour=graph[x][k], next_c=colour[x][k];
if(next_c==c){
continue;
}
edges.push(idx[x][k]);
for(int i=0;i<out[neighbour].size();i++){
if(out[neighbour][i]!=next_c){
ans(neighbour, out[neighbour][i]);
ok=1;
return;
}
}
if(marc[neighbour]<3){
out[x].push_back(next_c);
dfs(neighbour, next_c);
out[x].pop_back();
}
edges.pop();
}
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int t;
cin>>t;
while(t--){
int n, m;
cin>>n>>m;
for(int k=1;k<=n;k++){
graph[k].clear();
colour[k].clear();
idx[k].clear();
out[k].clear();
marc[k]=0;
}
while(!edges.empty()){
edges.pop();
}
e.clear();
ok=0;
for(int k=0;k<m;k++){
int a, b, c;
cin>>a>>b>>c;
e.push_back({{a, b}, c});
idx[k].push_back(k+1);
graph[a].push_back(b);
colour[a].push_back(c);
}
for(int k=1;k<=n;k++){
if(marc[k]<3){
dfs(k, 0);
}
if(ok){
break;
}
}
if(!ok){
cout<<"NO"<<endl;
}
}
}