#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 7;
int N, M, head[maxN], cnt;
struct Eddge {
  int nex, to;
  Eddge(int a = -1, int b = 0) : nex(a), to(b) {}
} edge[maxN];
inline void addEddge(int u, int v) {
  edge[cnt] = Eddge(head[u], v);
  head[u] = cnt++;
}
int dfn[maxN], low[maxN], tot, Stop, Stap[maxN], Belong[maxN], Bcnt, du[maxN],
    siz[maxN];
bool instack[maxN];
void Tarjan(int u) {
  dfn[u] = low[u] = ++tot;
  Stap[++Stop] = u;
  instack[u] = true;
  for (int i = head[u], v; ~i; i = edge[i].nex) {
    v = edge[i].to;
    if (!dfn[v]) {
      Tarjan(v);
      low[u] = min(low[u], low[v]);
    } else if (instack[v])
      low[u] = min(low[u], dfn[v]);
  }
  int v;
  if (low[u] == dfn[u]) {
    Bcnt++;
    siz[Bcnt] = 0;
    do {
      v = Stap[Stop--];
      instack[v] = false;
      Belong[v] = Bcnt;
      siz[Bcnt]++;
    } while (u != v);
  }
}
inline void init() {
  cnt = tot = Stop = Bcnt = 0;
  for (int i = 1; i <= N; i++) {
    head[i] = -1;
    du[i] = dfn[i] = 0;
    instack[i] = false;
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &N, &M);
    init();
    for (int i = 1, u, v; i <= M; i++) {
      scanf("%d%d", &u, &v);
      if (u == v) continue;
      addEddge(u, v);
    }
    for (int i = 1; i <= N; i++)
      if (!dfn[i]) Tarjan(i);
    if (Bcnt == 1) {
      printf("No\n");
      continue;
    }
    for (int u = 1; u <= N; u++) {
      for (int i = head[u], v; ~i; i = edge[i].nex) {
        v = edge[i].to;
        if (Belong[u] == Belong[v]) continue;
        du[Belong[u]]++;
      }
    }
    int id;
    for (id = 1; id <= Bcnt; id++)
      if (!du[id]) break;
    printf("Yes\n");
    printf("%d %d\n", siz[id], N - siz[id]);
    for (int i = 1; i <= N; i++)
      if (Belong[i] == id) printf("%d ", i);
    puts("");
    for (int i = 1; i <= N; i++)
      if (Belong[i] ^ id) printf("%d ", i);
    puts("");
  }
  return 0;
}
