#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int T, n, m;
int fir[N], from[N << 1], to[N << 1], cntt;
inline void add(int a, int b) {
  from[++cntt] = fir[a];
  fir[a] = cntt;
  to[cntt] = b;
}
int dfn[N], low[N], bel[N], dfs_clock, cnt;
int st[N], Top;
void Tarjan(int x) {
  st[++Top] = x;
  dfn[x] = low[x] = ++dfs_clock;
  for (int i = fir[x]; i; i = from[i]) {
    int &v = to[i];
    if (!dfn[v])
      Tarjan(v), low[x] = min(low[x], low[v]);
    else if (!bel[v])
      low[x] = min(low[x], dfn[v]);
  }
  if (low[x] != dfn[x]) return;
  cnt++;
  while (st[Top] != x) bel[st[Top--]] = cnt;
  bel[st[Top--]] = cnt;
}
int main() {
  scanf("%d", &T);
  while (T--) {
    for (int i = 1; i <= n; i++) fir[i] = dfn[i] = bel[i] = 0;
    cntt = cnt = dfs_clock = 0;
    scanf("%d%d", &n, &m);
    int a, b;
    for (int i = 1; i <= m; i++) {
      scanf("%d%d", &a, &b);
      if (a == b) continue;
      add(a, b);
    }
    for (int i = 1; i <= n; i++)
      if (!dfn[i]) Tarjan(i);
    if (cnt == 1) {
      printf("No\n");
      continue;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
      if (bel[i] == 1) ans++;
    printf("Yes\n%d %d\n", ans, n - ans);
    for (int i = 1; i <= n; i++)
      if (bel[i] == 1) printf("%d ", i);
    puts("");
    for (int i = 1; i <= n; i++)
      if (bel[i] != 1) printf("%d ", i);
    puts("");
  }
  return 0;
}
