#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1000010;
int T, n, m, flag, cnt;
vector<int> e[N], E[N];
int dfn[N], idx = 0, low[N], bl[N], lb, sta[N], top;
template <typename T>
void gi(T &x) {
  x = 0;
  register char c = getchar(), pre = 0;
  for (; c < '0' || c > '9'; pre = c, c = getchar())
    ;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10ll + (c ^ 48);
  if (pre == '-') x = -x;
}
int ksm(int x, int y = mod - 2) {
  int w = 1;
  for (; y; y >>= 1, x = 1ll * x * x % mod)
    if (y & 1) w = 1ll * x * w % mod;
  return w;
}
void tarjan(int u) {
  dfn[u] = low[u] = ++idx, sta[++top] = u;
  for (auto v : e[u]) {
    if (!dfn[v])
      tarjan(v), low[u] = min(low[u], low[v]);
    else if (!bl[v])
      low[u] = min(low[u], dfn[v]);
  }
  if (dfn[u] == low[u]) {
    bl[u] = ++lb;
    for (; sta[top] != u; --top) bl[sta[top]] = lb;
    --top;
  }
}
void solve() {
  gi(n), gi(m);
  for (int i = (1); i <= (n); i++)
    e[i].clear(), E[i].clear(), dfn[i] = low[i] = bl[i] = 0;
  for (int i = (1); i <= (m); i++) {
    int x, y;
    gi(x), gi(y);
    if (x == y) continue;
    e[y].push_back(x);
  }
  top = idx = lb = 0;
  for (int i = (1); i <= (n); i++)
    if (!dfn[i]) tarjan(i);
  if (lb == 1) {
    puts("No");
    return;
  }
  puts("Yes"), cnt = 0;
  for (int i = (1); i <= (n); i++)
    for (auto v : e[i])
      if (bl[i] != bl[v]) E[bl[i]].push_back(bl[v]);
  for (int i = (1); i <= (lb); i++)
    if (!E[i].size()) flag = i;
  for (int i = (1); i <= (n); i++)
    if (bl[i] != flag) ++cnt;
  printf("%d %d\n", cnt, n - cnt);
  for (int i = (1); i <= (n); i++)
    if (bl[i] != flag) printf("%d ", i);
  puts("");
  for (int i = (1); i <= (n); i++)
    if (bl[i] == flag) printf("%d ", i);
  puts("");
  puts("");
}
int main() {
  for (gi(T); T; --T) solve();
  return 0;
}
