#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\n";
  err(++it, args...);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long int INF = (long long int)(1e18) + 7;
struct SCC {
  int n, nScc;
  vector<int> visited, idx, order;
  vector<vector<int>> graph, rgraph;
  SCC(int _n) {
    n = _n;
    graph.resize(n + 1);
    rgraph.resize(n + 1);
    visited.resize(n + 1);
    idx.resize(n + 1);
    order.resize(n + 1);
    for (int i = 0; i <= n; i++) {
      graph[i].clear();
      rgraph[i].clear();
    }
  }
  void add_edge(int u, int v) {
    graph[u].push_back(v);
    rgraph[v].push_back(u);
  }
  void DFS(int u) {
    visited[u] = 1;
    for (auto v : graph[u]) {
      if (!visited[v]) {
        DFS(v);
      }
    }
    order.push_back(u);
  }
  void rDFS(int u) {
    visited[u] = 1;
    idx[u] = nScc;
    for (auto v : rgraph[u]) {
      if (!visited[v]) {
        rDFS(v);
      }
    }
  }
  void solve() {
    nScc = 0;
    order.clear();
    for (int i = 1; i <= n; i++) {
      visited[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
      if (!visited[i]) {
        DFS(i);
      }
    }
    reverse(order.begin(), order.end());
    for (int i = 1; i <= n; i++) {
      visited[i] = 0;
    }
    for (auto v : order) {
      if (!visited[v]) {
        rDFS(v);
        nScc++;
      }
    }
  }
};
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t, n, m, i, j, k, a, b, ans = 0;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    SCC g = SCC(n);
    for (i = 0; i < m; i++) {
      cin >> a >> b;
      g.add_edge(a, b);
    }
    g.solve();
    if (g.nScc == 1)
      cout << "NO"
           << "\n";
    else {
      vector<long long int> comp_a, comp_b;
      for (i = 1; i <= n; i++) {
        if (g.idx[i] == g.nScc - 1)
          comp_a.push_back(i);
        else
          comp_b.push_back(i);
      }
      cout << "YES"
           << "\n";
      cout << comp_a.size() << " " << comp_b.size() << "\n";
      for (auto it : comp_a) cout << it << " ";
      cout << "\n";
      for (auto it : comp_b) cout << it << " ";
      cout << "\n";
    }
  }
  return 0;
}
