#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long e;
void dfs(vector<long long> G[], vector<bool>& vis, long long s) {
  vis[s] = 1;
  for (auto i : G[s]) {
    if (!vis[i]) dfs(G, vis, i);
  }
  e = s;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long r = 0;
    vector<long long> G1[n + 1], G2[n + 1];
    for (long long i = 0; i < m; i++) {
      long long u, v;
      cin >> u >> v;
      G1[u].push_back(v);
      G2[v].push_back(u);
      r = v;
    }
    vector<bool> vis(n + 1, 0);
    for (long long i = 1; i <= n; i++) {
      if (!vis[i]) {
        dfs(G1, vis, i);
      }
    }
    vis.assign(n + 1, 0);
    dfs(G2, vis, e);
    set<long long> jury, participant;
    for (long long i = 1; i <= n; i++) {
      if (!vis[i]) {
        jury.insert(i);
      }
    }
    for (long long i = 1; i <= n; i++) {
      if (jury.find(i) == jury.end()) {
        participant.insert(i);
      }
    }
    if (jury.size() == n or participant.size() == n) {
      cout << "NO\n";
      continue;
    }
    cout << "YES\n";
    cout << jury.size() << " " << participant.size() << "\n";
    for (auto i : jury) cout << i << " ";
    cout << "\n";
    for (auto i : participant) cout << i << " ";
    cout << "\n";
  }
  return 0;
}
