#include <bits/stdc++.h>
using namespace std;
long long int fastMax(long long int x, long long int y) {
  return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y;
}
long long int fastMin(long long int x, long long int y) {
  return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x;
}
const long long int MAXN = 1e6 + 10;
vector<long long int> graph[MAXN], Rgraph[MAXN], order, comp[MAXN];
long long int visit[MAXN], num;
void dfs(long long int u) {
  visit[u] = true;
  for (long long int v : graph[u]) {
    if (!visit[v]) dfs(v);
  }
  order.push_back(u);
}
void Rdfs(long long int u) {
  visit[u] = true;
  comp[num].push_back(u);
  for (long long int v : Rgraph[u]) {
    if (!visit[v]) Rdfs(v);
  }
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 0; i <= n; i++) {
    graph[i].clear(), Rgraph[i].clear();
    visit[i] = 0;
    comp[i].clear();
  }
  for (long long int i = 1; i <= m; i++) {
    long long int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    Rgraph[v].push_back(u);
  }
  order.clear();
  for (long long int i = 1; i <= n; i++) {
    if (!visit[i]) dfs(i);
  }
  reverse(order.begin(), order.end());
  for (long long int i = 1; i <= n; i++) visit[i] = false;
  num = 0;
  for (long long int x : order) {
    if (!visit[x]) {
      Rdfs(x);
      num++;
    }
  }
  if (num == 1) {
    cout << "No\n";
  } else {
    cout << "Yes\n";
    cout << n - comp[0].size() << " " << comp[0].size() << '\n';
    for (long long int i = 1; i < num; i++) {
      for (long long int x : comp[i]) {
        cout << x << " ";
      }
    }
    cout << '\n';
    for (long long int x : comp[0]) {
      cout << x << " ";
    }
    cout << '\n';
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t;
  t = 1;
  cin >> t;
  for (long long int i = (1); i <= (t); ++i) {
    solve();
  }
}
