#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const int INF = 2147483600;
const int MAXN = 1000010;
int N, M;
bool vis[MAXN + 1];
int sq[MAXN + 1], top;
vector<int> Go[MAXN + 1], Bc[MAXN + 1];
int id[MAXN + 1], tot;
inline void dfs(int k) {
  if (vis[k]) return;
  vis[k] = 1;
  for (int i = 0, l = Go[k].size(); i < l; i++) dfs(Go[k][i]);
  sq[++top] = k;
}
inline void dfs2(int k) {
  if (id[k]) return;
  id[k] = tot;
  for (int i = 0, l = Bc[k].size(); i < l; i++) dfs2(Bc[k][i]);
}
inline void solve() {
  N = read(), M = read();
  for (int i = 1; i <= N; i++) Go[i].clear(), Bc[i].clear(), id[i] = vis[i] = 0;
  top = tot = 0;
  for (int i = 1; i <= M; i++) {
    int u = read(), v = read();
    if (u != v) Go[u].push_back(v), Bc[v].push_back(u);
  }
  for (int i = 1; i <= N; i++)
    if (!vis[i]) dfs(i);
  for (int i = top; i >= 1; i--)
    if (!id[sq[i]]) ++tot, dfs2(sq[i]);
  if (tot == 1) {
    puts("No");
    return;
  }
  int ret = 0;
  for (int i = 1; i <= N; i++)
    if (id[i] == tot) ++ret;
  puts("Yes");
  printf("%d %d\n", ret, N - ret);
  for (int i = 1; i <= N; i++)
    if (id[i] == tot) printf("%d ", i);
  printf("\n");
  for (int i = 1; i <= N; i++)
    if (id[i] < tot) printf("%d ", i);
  printf("\n");
}
int main() {
  int T = read();
  while (T--) {
    solve();
  }
  return 0;
}
