#include <bits/stdc++.h>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
vector<vector<pair<pair<int,int>,int>>> neigh;
vector<unordered_map<int,int>> visited;
vector<int> visitedC;
vector<int> ans;
pair<int,int> st;
bool dfs(int x, int c){
if(visited[x][c]==2) return false;
if(visited[x][c]==1) {
st={x,c};
return true;
}
if(visitedC[x]>2) return false;
visited[x][c]=1;
visitedC[x]++;
for (auto u : neigh[x])
{
if(u.first.second==c) continue;
if(dfs(u.first.first,u.first.second)) {
if((x!=st.first||c!=st.second)&&st.first>=0) ans.push_back(u.second);
else if(x==st.first&&c==st.second){
ans.push_back(u.second);
st={-1,-1};
}
return true;
}
}
visited[x][c]=2;
return false;
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int t; cin >> t;
while(t--){
int n,m; cin >> n >> m;
neigh.resize(n);
visited.resize(n);
visitedC.resize(n,0);
vector<vector<int>> clr(n);
ans.clear();
st={-1,-1};
for (int i = 0; i < n; i++)
{
visitedC[i]=0;
neigh[i].clear();
visited[i].clear();
}
for (int i = 0; i < m; i++)
{
int a, b,c; cin >> a >> b >> c; a--; b--; c--;
neigh[a].push_back({{b,c},i+1});
clr[b].push_back(c);
}
bool b=false;
for (int i = 0; i < n; i++)
{
for (auto j : clr[i]){
if(visited[i][j]) continue;
if(dfs(i,j)) b=true;
if(b) break;
}
if(b) break;
}
if(b) {
cout << "YES\n";
cout << sz(ans) << " ";
for (int i = 0; i < sz(ans); i++) cout << ans[sz(ans)-i-1] << " ";
cout << "\n";
}
else cout << "NO\n";
}
return 0;
}