#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
struct Edge {
  int nxt, to;
} e[maxn];
int hd[maxn], e_cnt;
void add(int u, int v) {
  e[++e_cnt] = (Edge){hd[u], v};
  hd[u] = e_cnt;
}
int n, m, scc_cnt, clk, dfn[maxn], low[maxn], scc[maxn];
stack<int> stk;
bool ins[maxn];
void tarjan(int u) {
  dfn[u] = low[u] = ++clk;
  stk.push(u);
  ins[u] = true;
  for (int i = hd[u]; i; i = e[i].nxt)
    if (!dfn[e[i].to])
      tarjan(e[i].to), low[u] = min(low[u], low[e[i].to]);
    else if (ins[e[i].to])
      low[u] = min(low[u], dfn[e[i].to]);
  if (dfn[u] == low[u]) {
    int x;
    scc_cnt++;
    do {
      x = stk.top();
      stk.pop();
      ins[x] = false;
      scc[x] = scc_cnt;
    } while (x != u);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
      int a, b;
      cin >> a >> b;
      add(a, b);
    }
    for (int i = 1; i <= n; i++)
      if (!dfn[i]) tarjan(i);
    if (scc_cnt == 1)
      cout << "No" << '\n';
    else {
      cout << "Yes" << '\n';
      int cnt = 0;
      for (int i = 1; i <= n; i++)
        if (scc[i] == 1) cnt++;
      cout << cnt << ' ' << n - cnt << '\n';
      for (int i = 1; i <= n; i++)
        if (scc[i] == 1) cout << i << ' ';
      cout << '\n';
      for (int i = 1; i <= n; i++)
        if (scc[i] != 1) cout << i << ' ';
      cout << '\n';
    }
    for (int i = 1; i <= n; i++) hd[i] = dfn[i] = low[i] = clk = scc_cnt = 0;
    e_cnt = 0;
  }
  return 0;
}
