#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline int read(T& x) {
  x = 0;
  char c = getchar(), f = 1;
  while (c > '9' || c < '0') {
    if (c == '-') f = -1;
    if (c == -1) return -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  x *= f;
  return 1;
}
template <typename T, typename... Args>
inline int read(T& x, Args&... args) {
  return read(x) + read(args...);
}
template <typename T>
inline int write(T x) {
  if (x < 0) return putchar('-') & write((~x) + 1);
  if (x / 10) return write(x / 10) & putchar(x % 10 | 48);
  return putchar(x | 48);
}
template <typename T>
inline int write(T x, char c) {
  return write(x) + putchar(c);
}
int n, m;
struct edge {
  int u, v, nxt;
} e[1000005 << 1];
int f[1000005], tot = 1;
inline void addEdge(int u, int v) {
  tot++, e[tot].u = u, e[tot].v = v, e[tot].nxt = f[u], f[u] = tot;
}
int dfn[1000005], low[1000005], idx;
int bel[1000005], siz[1000005], scc;
bool ins[1000005];
int sta[1000005], tp;
inline void tarjan(int x, int fa) {
  dfn[x] = low[x] = ++idx;
  sta[++tp] = x;
  ins[x] = 1;
  for (int i = f[x]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (!dfn[v]) {
      tarjan(v, x);
      low[x] = ((low[x]) < (low[v]) ? (low[x]) : (low[v]));
    } else if (ins[v])
      low[x] = ((low[x]) < (dfn[v]) ? (low[x]) : (dfn[v]));
  }
  if (dfn[x] == low[x]) {
    int v;
    scc++;
    do {
      v = sta[tp--];
      bel[v] = scc;
      siz[scc]++;
      ins[v] = 0;
    } while (v != x);
  }
}
signed main() {
  int t;
  read(t);
  while (t--) {
    read(n, m);
    tot = idx = scc = 0;
    for (int i = 1; i <= n; i++) bel[i] = dfn[i] = low[i] = f[i] = siz[i] = 0;
    for (int i = 1; i <= m; i++) {
      int u, v;
      read(u, v);
      if (u != v) addEdge(u, v);
    }
    for (int i = 1; i <= n; i++)
      if (!dfn[i]) tarjan(i, -1);
    if (scc == 1) {
      puts("No");
      continue;
    }
    puts("Yes");
    write(siz[1], ' '), write(n - siz[1], '\n');
    for (int i = 1; i <= n; i++)
      if (bel[i] == 1) write(i, ' ');
    putchar(10);
    for (int i = 1; i <= n; i++)
      if (bel[i] != 1) write(i, ' ');
    putchar(10);
  }
}
