#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> adj, adj2, scc;
stack<long long> s;
vector<long long> par;
vector<bool> viz;
void dfs(long long v) {
  viz[v] = 1;
  for (auto p : adj[v])
    if (!viz[p]) dfs(p);
  s.push(v);
}
void dfs2(long long v, long long p) {
  viz[v] = 1;
  par[v] = p;
  scc[p].push_back(v);
  for (auto i : adj2[v])
    if (!viz[i]) dfs2(i, p);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, i, j, x, t, m, y;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    vector<long long> v;
    adj.assign(n + 1, v);
    adj2.assign(n + 1, v);
    scc.assign(n + 1, v);
    for (i = 0; i < m; i++) {
      cin >> x >> y;
      if (x != y) {
        adj[x].push_back(y);
      }
    }
    viz.assign(n + 1, 0);
    for (i = 1; i <= n; i++)
      if (!viz[i]) dfs(i);
    for (i = 1; i <= n; i++)
      for (auto p : adj[i]) adj2[p].push_back(i);
    viz.assign(n + 1, 0);
    par.assign(n + 1, 0);
    for (i = 1; i <= n; i++) par[i] = i;
    while (!s.empty()) {
      if (!viz[s.top()]) dfs2(s.top(), s.top());
      s.pop();
    }
    x = 0;
    for (i = 1; i <= n; i++) {
      if (!scc[i].empty()) x++;
    }
    if (x == 1) {
      cout << "No\n";
      continue;
    }
    cout << "Yes\n";
    for (i = 1; i <= n; i++) {
      if (!scc[i].empty()) {
        unordered_map<long long, long long> mp;
        bool ok = 1;
        for (auto p : scc[i]) mp[p]++;
        for (auto p : scc[i]) {
          for (auto q : adj[p]) {
            if (mp[q] == 0) {
              ok = 0;
              break;
            }
          }
          if (!ok) break;
        }
        if (ok) {
          x = i;
          break;
        }
      }
    }
    vector<long long> ans(n + 1, 0);
    for (auto p : scc[x]) ans[p] = 1;
    for (i = 1; i <= n; i++) {
      if (ans[i] == 0) ans[i] = 2;
    }
    x = scc[x].size();
    cout << x << " " << n - x << "\n";
    for (i = 1; i <= n; i++) {
      if (ans[i] == 1) cout << i << " ";
    }
    cout << "\n";
    for (i = 1; i <= n; i++) {
      if (ans[i] == 2) cout << i << " ";
    }
    cout << "\n";
  }
}
