#include <bits/stdc++.h>
using namespace std;
const int maxd = 2e6 + 10;
struct edge {
  int v, net;
} e[maxd << 1];
int f[maxd], eid;
void insert(int a, int b) {
  e[eid].v = b;
  e[eid].net = f[a];
  f[a] = eid++;
}
int dfn[maxd], low[maxd], idx = 0;
int belong[maxd], scc = 0;
int s[maxd], top = 0, n, m, sz[2], ans[maxd];
bool in_stack[maxd];
void init(int n) {
  fill(f, f + 1 + n, -1);
  fill(dfn, dfn + 1 + n, 0);
  sz[1] = sz[0] = scc = idx = eid = 0;
}
void tarjan(int u) {
  dfn[u] = low[u] = ++idx;
  s[top++] = u;
  in_stack[u] = true;
  for (int i = f[u]; i != -1; i = e[i].net) {
    int v = e[i].v;
    if (!dfn[v]) {
      tarjan(v);
      low[u] = min(low[u], low[v]);
    } else if (in_stack[v])
      low[u] = min(low[u], dfn[v]);
  }
  if (dfn[u] == low[u]) {
    ++scc;
    do {
      belong[s[--top]] = scc;
      in_stack[s[top]] = false;
    } while (s[top] != u);
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &n, &m);
    init(n * 2);
    for (int i = 1; i <= m; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      if (x == y) continue;
      insert(x, y), insert(y + n, x + n);
    }
    for (int i = 1; i <= 2 * n; i++)
      if (!dfn[i]) tarjan(i);
    if (scc == 2) {
      printf("No\n");
      continue;
    }
    int now = 1;
    for (int i = 1; i <= n; i++)
      if (belong[i] == 1) now = 0;
    for (int i = 1; i <= n; i++) {
      if (belong[i + now * n] == 1)
        ans[i] = now, sz[now]++;
      else
        sz[now ^ 1]++, ans[i] = now ^ 1;
    }
    printf("Yes\n%d %d\n", sz[0], sz[1]);
    for (int i = 1; i <= n; i++)
      if (!ans[i]) printf("%d ", i);
    putchar(10);
    for (int i = 1; i <= n; i++)
      if (ans[i]) printf("%d ", i);
    putchar(10);
  }
  return 0;
}
