#include <bits/stdc++.h>
using namespace std;
template <typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
template <typename T>
inline T mod(T n, T mod) {
  T res = n % mod;
  if (res < 0) res += mod;
  return res;
}
const int N = 1e6 + 5;
vector<int> adj[N], g[N], stk;
int tin[N], low[N], comp[N], tempo, idComp, degree[N];
void tarjan(int v) {
  tin[v] = low[v] = ++tempo;
  stk.emplace_back(v);
  for (int u : adj[v]) {
    if (!tin[u]) tarjan(u);
    if (comp[u] == -1) {
      low[v] = min(low[v], low[u]);
    }
  }
  if (tin[v] == low[v]) {
    idComp++;
    while (1) {
      int u = stk.back();
      stk.pop_back();
      comp[u] = idComp;
      if (u == v) break;
    }
  }
}
void init(int n) {
  tempo = 0, idComp = 0;
  for (int i = 1; i <= n; i++) {
    adj[i].clear();
    tin[i] = low[i] = degree[i] = 0;
    comp[i] = -1;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    init(n);
    vector<int> a(m), b(m);
    for (int i = 0; i < m; i++) {
      cin >> a[i] >> b[i];
      adj[a[i]].push_back(b[i]);
    }
    for (int i = 1; i <= n; i++) {
      if (!tin[i]) {
        tarjan(i);
      }
    }
    if (idComp == 1) {
      cout << "No\n";
      continue;
    }
    for (int i = 0; i < m; i++) {
      if (comp[a[i]] != comp[b[i]]) {
        degree[comp[b[i]]]++;
      }
    }
    int idxPlayers = 0;
    for (int i = 1; i <= idComp; i++) {
      if (!degree[i]) {
        idxPlayers = i;
        break;
      }
    }
    vector<int> p, jud;
    for (int i = 1; i <= n; i++) {
      if (comp[i] == idxPlayers)
        p.push_back(i);
      else
        jud.push_back(i);
    }
    if (!((int)(p).size()) or !((int)(jud).size())) {
      cout << "No\n";
      continue;
    }
    cout << "Yes\n";
    cout << ((int)(jud).size()) << ' ' << ((int)(p).size()) << '\n';
    for (int x : jud) {
      cout << x << ' ';
    }
    cout << '\n';
    for (int x : p) {
      cout << x << ' ';
    }
    cout << '\n';
  }
  return 0;
}
