#include <bits/stdc++.h>
using namespace std;
const int MAX_M = 1000005;
const int MAX_G = 3000005;
vector<pair<int, int>> in[MAX_M], out[MAX_M];
vector<int> graf[MAX_G];
bool odw[MAX_G], ter[MAX_G];
vector<int> stak, cykl;
bool czy = false;
int wie = -1;
int from[MAX_M], to[MAX_M], attr[MAX_M];
void dfs(int x)
{
if (wie != -1) return;
odw[x] = true;
ter[x] = true;
stak.push_back(x);
for (int i : graf[x])
{
if (ter[i] && wie == -1)
{
czy = true;
wie = i;
while (stak.back() != wie)
{
cykl.push_back(stak.back());
stak.pop_back();
}
cykl.push_back(stak.back());
stak.pop_back();
return;
}
if (!odw[i])
{
dfs(i);
}
}
stak.pop_back();
ter[x] = false;
}
void solve()
{
stak.clear();
cykl.clear();
int mil = 1000000;
int n, m, a, b, c;
cin >> n >> m;
for (int i = 0; i <= n; ++i)
{
in[i].clear();
out[i].clear();
}
for (int i = 0; i < 3 * mil; ++i)
{
graf[i].clear();
odw[i] = false;
ter[i] = false;
}
for (int i = 0; i < m; ++i)
{
cin >> a >> b >> c;
from[i] = a;
to[i] = b;
attr[i] = c;
out[a].push_back({c, i});
in[b].push_back({c, i});
}
for (int i = 0; i < m; ++i)
{
graf[mil + i].push_back(i);
graf[2 * mil + i].push_back(i);
}
for (int i = 1; i <= n; ++i)
{
sort(in[i].begin(), in[i].end());
sort(out[i].begin(), out[i].end());
for (int j = 0; j < (int)out[i].size() - 1; ++j)
{
graf[mil + out[i][j].second].push_back(mil + out[i][j + 1].second);
graf[2 * mil + out[i][j + 1].second].push_back(2 * mil + out[i][j].second);
}
}
for (int i = 1; i <= n; ++i)
{
int l = 0, p = 0;
for (int j = 0; j < (int)in[i].size(); ++j)
{
int walk_in = in[i][j].second;
if ((int)out[i].size() == 0) continue;
while (l < (int)out[i].size() && out[i][l].first < in[i][j].first)
++l;
if (l < (int)out[i].size() && out[i][l].first == in[i][j].first)
{
p = l;
while (p + 1 < (int)out[i].size() && out[i][p + 1].first == in[i][j].first)
++p;
if (l > 0)
{
int walk_out = out[i][l - 1].second;
if (to[walk_in] == from[walk_out] && attr[walk_in] != attr[walk_out])
graf[walk_in].push_back(2 * mil + walk_out);
}
if (p + 1 < (int)out[i].size())
{
int walk_out = out[i][p + 1].second;
if (to[walk_in] == from[walk_out] && attr[walk_in] != attr[walk_out])
graf[walk_in].push_back(mil + walk_out);
}
}
else
{
int walk_out = out[i][0].second;
if (to[walk_in] == from[walk_out] && attr[walk_in] != attr[walk_out])
graf[walk_in].push_back(mil + walk_out);
}
}
}
for (int i = 0; i < m; ++i)
{
if (!odw[i]) dfs(i);
if (wie != -1)
{
cout << "YES\n";
int count = 0;
vector<int> res;
for (int j : cykl)
{
if (j < mil)
{
++count;
res.push_back(j + 1);
}
}
cout << count << ' ';
for (int id : res) cout << id << ' ';
cout << '\n';
wie = -1;
return;
}
}
cout << "NO\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}