#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
struct node {
  int to, nxt;
} e[2][maxn << 1];
int n, m, cnt, tot[2], head[2][maxn];
bool vis[maxn];
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void print(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
void write(int x) {
  print(x);
  puts("");
}
void init() {
  cnt = tot[0] = tot[1] = 0;
  for (int i = 1; i <= n; i++) vis[i] = 0;
  for (int i = 1; i <= n; i++) head[0][i] = head[1][i] = 0;
}
void add(int opt, int u, int v) {
  e[opt][++tot[opt]].to = v;
  e[opt][tot[opt]].nxt = head[opt][u];
  head[opt][u] = tot[opt];
}
void dfs(int opt, int x) {
  vis[x] = 1;
  cnt++;
  for (int i = head[opt][x], v = e[opt][i].to; i;
       i = e[opt][i].nxt, v = e[opt][i].to)
    if (!vis[v]) dfs(opt, v);
}
signed main() {
  int T = read();
  while (T--) {
    n = read();
    m = read();
    init();
    for (int i = 1; i <= m; i++) {
      int u = read(), v = read();
      add(0, u, v);
      add(1, v, u);
    }
    dfs(0, 1);
    bool flag = 1;
    if (cnt == n) {
      cnt = 0;
      for (int i = 1; i <= n; i++) vis[i] = 0;
      dfs(1, 1);
      if (cnt == n) {
        puts("No");
        continue;
      }
      cnt = n - cnt;
      flag = 0;
    }
    printf("Yes\n%d %d\n", cnt, n - cnt);
    for (int i = 1; i <= n; i++)
      if (vis[i] == flag) printf("%d ", i);
    puts("");
    for (int i = 1; i <= n; i++)
      if (vis[i] != flag) printf("%d ", i);
    puts("");
  }
  return 0;
}
