#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <fstream>
#include <iterator>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cctype>
#include <string>
#include <cassert>
#include <set>
#include <bitset>
#include <unordered_set>
#include <numeric>
#define all(a) a.begin(), a.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ppi pair<int,pair<int,int>>
#define int int64_t
using namespace std;
// /\_/\
// (= ._.)
// / > \>
// encouraging cat
const int INF = 10000000000000000;
//const int mod = 1000000007;
const int mod = 998244353;
const int MAXN = 10;
//ifstream fin('xor.in');
//ofstream fout('xor.out');
struct Edge {
int to, col, index;
};
vector<vector<Edge>> adj;
bool vis[MAXN][2], curr_vis[MAXN][2];
int in[MAXN][2];
vector<int> curr_path, ans;
bool found = false;
bool stop = false;
pair<int,int> target = {-1, -1};
void dfs(int node, int tp, int prev)
{
if (node == target.first && tp == target.second)
{
stop = true;
}
vis[node][tp] = true;
curr_vis[node][tp] = true;
for (auto edge: adj[node])
{
if (found)
{
continue;
}
int nxt_tp = 0;
if (edge.col == in[edge.to][0])
{
nxt_tp++;
}
if (edge.col == in[node][tp])
{
continue;
}
if (curr_vis[edge.to][nxt_tp])
{
found = true;
target = {edge.to, nxt_tp};
ans.pb(edge.index);
continue;
}
if (in[edge.to][nxt_tp] == -1)
{
in[edge.to][nxt_tp] = edge.col;
}
curr_path.pb(edge.index);
dfs(edge.to, nxt_tp, node);
if (node == target.first && tp == target.second)
{
ans.pb(curr_path[curr_path.size() - 1]);
stop = true;
}
if (found && !stop)
{
ans.pb(curr_path[curr_path.size() - 1]);
}
curr_path.pop_back();
}
curr_vis[node][tp] = false;
}
signed main()
{
int t;
cin >> t;
while (t--)
{
int n,m;
cin >> n >> m;
adj.clear();
adj.resize(n);
vector<Edge> edges(m);
ans.clear();
curr_path.clear();
target = {-1, -1};
found = false;
stop = false;
for (int i = 0;i < n;i++)
{
vis[i][0] = false;
vis[i][1] = false;
in[i][0] = -1;
in[i][1] = -1;
}
for (int i = 0;i < m;i++)
{
int u,v,c;
cin >> u >> v >> c;
u--,v--;
adj[u].pb({v, c, i + 1});
edges[i] = {v, c, i + 1};
vis[i][0] = false;
}
for (int i = 0;i < m;i++)
{
int tp = 0;
if (edges[i].col != in[edges[i].to][tp] && in[edges[i].to][tp] != -1)
{
tp++;
}
if (in[edges[i].to][tp] == -1)
{
in[edges[i].to][tp] = edges[i].col;
}
if (vis[i][tp])
{
continue;
}
dfs(edges[i].to, tp, -1);
}
if (found)
{
cout << "YES" << '\n';
reverse(all(ans));
for (auto i: ans)
{
cout << i << " ";
}
cout << '\n';
}
else
{
cout << "NO" << '\n';
}
}
return 0;
}