#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 5e5 + 5;
long long fact[N], invfact[N];
long long pow(long long a, long long b, long long m) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans;
}
vector<long long> vp[1000005];
long long vis[1000005];
long long vis1[1000005];
vector<long long> v1[1000005];
stack<long long> st;
long long cnt = 0;
void dfs(long long n) {
  vis[n] = 1;
  for (auto it : vp[n]) {
    if (!vis[it]) {
      dfs(it);
    }
  }
  st.push(n);
}
void dfs1(long long n) {
  cnt++;
  vis1[n] = 1;
  for (auto it : v1[n]) {
    if (!vis1[it]) {
      dfs1(it);
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long x, y;
    for (long long i = 1; i <= m; i++) {
      cin >> x >> y;
      if (x != y) {
        vp[x].push_back(y);
        v1[y].push_back(x);
      }
    }
    cnt = 0;
    for (long long i = 1; i <= n; i++) {
      if (!vis[i]) dfs(i);
    }
    dfs1(st.top());
    if (cnt == n)
      cout << "No" << endl;
    else {
      cout << "Yes" << endl;
      cout << n - cnt << " " << cnt << endl;
      for (long long i = 1; i <= n; i++)
        if (!vis1[i]) cout << i << " ";
      cout << endl;
      for (long long i = 1; i <= n; i++)
        if (vis1[i]) cout << i << " ";
      cout << endl;
    }
    for (long long i = 1; i <= n; i++) {
      vp[i].clear();
      v1[i].clear();
      vis[i] = 0;
      vis1[i] = 0;
    }
    while (!st.empty()) st.pop();
  }
}
