#include <bits/stdc++.h>
using namespace std;
set<long long> jury;
vector<vector<long long> > adj, adj2;
vector<long long> vis, arr;
void solve(long long s) {
  vis[s] = 1;
  for (auto x : adj[s]) {
    if (!vis[x]) {
      solve(x);
    }
  }
  arr.push_back(s);
}
void dfs(long long s) {
  vis[s] = 1;
  for (auto x : adj2[s]) {
    if (!vis[x]) {
      dfs(x);
    }
  }
}
void vale(long long s) {
  vis[s] = 1;
  jury.insert(s);
  for (auto x : adj[s]) {
    if (!vis[x]) {
      vale(x);
    }
  }
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    jury.clear();
    arr.clear();
    adj.assign(n + 5, vector<long long>());
    adj2.assign(n + 5, vector<long long>());
    for (long long i = 0; i < m; i++) {
      long long a, b;
      cin >> a >> b;
      adj[a].push_back(b);
      adj2[b].push_back(a);
    }
    vis.assign(n + 5, 0);
    for (long long i = 1; i < n + 1; i++) {
      if (!vis[i]) {
        solve(i);
      }
    }
    reverse(arr.begin(), arr.end());
    vis.assign(n + 5, 0);
    long long a = 0, b = 0;
    for (auto x : arr) {
      if (!vis[x]) {
        if (a == 0) {
          a = x;
        } else {
          b = x;
        }
        dfs(x);
      }
    }
    bool ok = 1;
    if (b != 0) {
      vis.assign(n + 5, 0);
      vale(a);
      if (jury.size() == n) {
        jury.clear();
        vis.assign(n + 5, 0);
        vale(b);
      }
      set<long long> part;
      for (long long i = 1; i < n + 1; i++) {
        if (!jury.count(i)) {
          part.insert(i);
        }
      }
      cout << "Yes" << endl;
      cout << jury.size() << " " << part.size() << endl;
      for (auto x : jury) {
        cout << x << " ";
      }
      cout << endl;
      for (auto x : part) {
        cout << x << " ";
      }
      cout << endl;
    } else {
      ok = 0;
    }
    if (!ok) {
      cout << "No" << endl;
    }
  }
}
