#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 7;
int N, M;
vector<int> G[MAXN];
int solve() {
  cin >> N >> M;
  for (int i = 1; i <= N; ++i) G[i].clear();
  for (int i = 1; i <= M; ++i) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
  }
  vector<int> low(N + 1, 0), vis(N + 1, 0);
  int curTime = 0;
  function<int(int)> dfs = [&](int u) {
    low[u] = vis[u] = ++curTime;
    int x;
    for (int v : G[u]) {
      if (!vis[v]) {
        if (x = dfs(v)) return x;
        low[u] = min(low[u], low[v]);
      } else {
        low[u] = min(low[u], vis[v]);
      }
    }
    if (low[u] == vis[u] && u != 1) return u;
    if (u == 1 && count(vis.begin() + 1, vis.end(), 0)) return 1;
    return 0;
  };
  int root = dfs(1);
  if (!root) return cout << "No\n", 0;
  fill(begin(vis), end(vis), 0);
  function<void(int)> dfsAssign = [&](int u) {
    vis[u] = 1;
    for (int v : G[u]) {
      if (!vis[v]) dfsAssign(v);
    }
  };
  dfsAssign(root);
  cout << "Yes\n";
  int p = count(vis.begin() + 1, vis.end(), 0);
  cout << N - p << ' ' << p << '\n';
  for (int i = 1; i <= N; ++i)
    if (vis[i]) cout << i << ' ';
  cout << '\n';
  for (int i = 1; i <= N; ++i)
    if (!vis[i]) cout << i << ' ';
  cout << '\n';
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
