#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int t, n, m, u, v, dfn[N], low[N], scc[N], times, sccno;
int S[N], top, vis[N];
vector<int> to[N];
void tarjan(int u) {
  dfn[u] = low[u] = ++times;
  S[++top] = u;
  vis[u] = 1;
  for (int sz = to[u].size(), i = 0, v; i < sz; i++) {
    v = to[u][i];
    if (vis[v])
      low[u] = min(low[u], dfn[v]);
    else if (!dfn[v])
      tarjan(v), low[u] = min(low[u], low[v]);
  }
  if (dfn[u] == low[u]) {
    scc[u] = ++sccno;
    while (S[top] != u) {
      vis[S[top]] = 0;
      scc[S[top--]] = sccno;
    }
    vis[S[top--]] = 0;
  }
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) to[i].clear();
    for (int i = 1; i <= m; i++) scanf("%d%d", &u, &v), to[u].push_back(v);
    for (int i = 1; i <= n; i++) dfn[i] = low[i] = scc[i] = 0;
    times = sccno = 0;
    for (int i = 1; i <= n; i++)
      if (!dfn[i]) tarjan(i);
    if (sccno == 1)
      puts("No");
    else {
      int cnt = 0;
      puts("Yes");
      for (int i = 1; i <= n; i++)
        if (scc[i] == 1) ++cnt;
      printf("%d %d\n", cnt, n - cnt);
      for (int i = 1; i <= n; i++)
        if (scc[i] == 1) printf("%d ", i);
      puts("");
      for (int i = 1; i <= n; i++)
        if (scc[i] != 1) printf("%d ", i);
      puts("");
    }
  }
  return 0;
}
