#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 7;
const long long MOD = 1e9 + 7;
struct Edge {
  int to, next;
} edge[MAXN * 2];
int head[MAXN], tot;
int n, m;
int dfn[MAXN], low[MAXN];
bool vis[MAXN];
int scc[MAXN];
int block_cnt;
int siz[MAXN];
int sig;
stack<int> S;
void init() {
  tot = 0;
  sig = 0;
  block_cnt = 0;
  for (int i = 0; i <= n; i++) {
    head[i] = -1;
    vis[i] = dfn[i] = scc[i] = siz[i] = low[i] = 0;
  }
}
void addEdge(int from, int to) {
  edge[++tot].to = to;
  edge[tot].next = head[from];
  head[from] = tot;
}
void Tarjan(int x) {
  vis[x] = true;
  dfn[x] = low[x] = ++block_cnt;
  S.push(x);
  for (int i = head[x]; i != -1; i = edge[i].next) {
    int y = edge[i].to;
    if (!dfn[y]) {
      Tarjan(y);
      low[x] = min(low[x], low[y]);
    } else if (vis[y])
      low[x] = min(low[x], dfn[y]);
  }
  if (dfn[x] == low[x]) {
    sig++;
    while (true) {
      int temp = S.top();
      S.pop();
      siz[sig]++;
      vis[temp] = false;
      scc[temp] = sig;
      if (temp == x) break;
    }
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d %d", &n, &m);
    init();
    for (int i = 1; i <= m; i++) {
      int a, b;
      scanf("%d %d", &a, &b);
      if (a != b) addEdge(a, b);
    }
    for (int i = 1; i <= n; i++) {
      if (!dfn[i]) Tarjan(i);
    }
    if (siz[1] == n) {
      printf("No\n");
    } else {
      printf("Yes\n");
      printf("%d %d\n", siz[1], n - siz[1]);
      for (int i = 1; i <= n; i++) {
        if (scc[i] == 1) printf("%d ", i);
      }
      printf("\n");
      for (int i = 1; i <= n; i++) {
        if (scc[i] != 1) printf("%d ", i);
      }
      printf("\n");
    }
  }
}
