#include <bits/stdc++.h>
using namespace std;
int get() {
  int x = 0;
  char s = getchar();
  while (s < '0' || s > '9') s = getchar();
  while (s >= '0' && s <= '9')
    x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();
  return x;
}
int Min(const int x, const int y) {
  if (x < y) return x;
  return y;
}
const int M = 1e6 + 5;
int n, m, head[M], cntedge, dfn[M], low[M], tot, cntscc, scc[M], siz[M];
bool in[M];
stack<int> st;
struct edge {
  int to, nxt;
  edge() {}
  edge(const int T, const int NX) { to = T, nxt = NX; }
} e[M];
void add(const int u, const int v) {
  e[++cntedge] = edge(v, head[u]), head[u] = cntedge;
}
void dfs(const int u) {
  dfn[u] = low[u] = ++tot;
  in[u] = 1;
  st.push(u);
  int v;
  for (int i = head[u]; i; i = e[i].nxt)
    if (!dfn[v = e[i].to])
      dfs(v), low[u] = Min(low[u], low[v]);
    else if (in[v])
      low[u] = Min(low[u], dfn[v]);
  if (low[u] == dfn[u]) {
    ++cntscc;
    do {
      v = st.top(), st.pop();
      in[v] = 0;
      scc[v] = cntscc;
      ++siz[cntscc];
    } while (v ^ u);
  }
}
void init() {
  n = get(), m = get();
  for (int i = 1; i <= n; ++i) head[i] = dfn[i] = low[i] = siz[i] = scc[i] = 0;
  cntedge = tot = cntscc = 0;
  for (int u, v; m--;) {
    u = get(), v = get();
    if (u ^ v) add(u, v);
  }
}
int main() {
  for (int T = get(); T--;) {
    init();
    for (int i = 1; i <= n; ++i)
      if (!dfn[i]) dfs(i);
    if (cntscc == 1) {
      printf("No\n");
      continue;
    }
    printf("Yes\n%d %d\n", siz[1], n - siz[1]);
    for (int i = 1; i <= n; ++i)
      if (scc[i] == 1) printf("%d ", i);
    putchar('\n');
    for (int i = 1; i <= n; ++i)
      if (scc[i] ^ 1) printf("%d ", i);
    putchar('\n');
  }
  return 0;
}
