#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v;
vector<int> vt, vans;
int in[1100000], rt[1100000];
bool flag = false;
void dfs(int n) {
  vt.push_back(n);
  rt[n] = in[n] = vt.size();
  for (int i : v[n]) {
    if (in[i] == 0) dfs(i);
    if (flag) return;
    rt[n] = min(rt[n], rt[i]);
  }
  if (rt[n] == in[n]) {
    flag = true;
    vans.assign(find(vt.begin(), vt.end(), n), vt.end());
  }
}
void vreset(int p) {
  v.clear();
  v.resize(p);
  vt.clear();
  vans.clear();
  fill(in, in + p, 0);
  fill(rt, rt + p, 0);
  flag = false;
}
void rdfs(int p) {
  dfs(0);
  if (vans.size() == p) {
    cout << "NO" << endl;
    return;
  }
  sort(vans.begin(), vans.end());
  cout << "YES" << endl << vans.size() << ' ' << p - vans.size() << endl;
  for (int j : vans) cout << j + 1 << ' ';
  cout << endl;
  auto it = vans.begin();
  for (int j = 0; j < p; ++j) {
    if (it != vans.end() && j == *it)
      ++it;
    else
      cout << j + 1 << ' ';
  }
  cout << endl;
}
int main() {
  int t, p, e;
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> p >> e;
    vreset(p);
    for (int i = 0; i < e; ++i) {
      int a1, a2;
      cin >> a1 >> a2;
      if (a1 != a2) v[a1 - 1].push_back(a2 - 1);
    }
    rdfs(p);
  }
}
