#include <bits/stdc++.h>
const int N = 1e6 + 5;
int t, n, m, rt, ans, a[N], b[N], k[N];
int cnt, End[N], Next[N], Last[N];
int tot, vis[N], dfn[N], low[N], top, s[N], c[N], col;
void add(int x, int y) {
  End[++cnt] = y;
  Next[cnt] = Last[x];
  Last[x] = cnt;
}
void xxx(int x) {
  s[++top] = x;
  vis[x] = 1;
  dfn[x] = low[x] = ++tot;
  for (int i = Last[x], y; i; i = Next[i])
    if (!dfn[y = End[i]])
      xxx(y), low[x] = std::min(low[x], low[y]);
    else if (vis[y])
      low[x] = std::min(low[x], dfn[y]);
  if (dfn[x] == low[x]) {
    for (++col; s[top] != x;) {
      vis[s[top]] = 0;
      c[s[top--]] = col;
    }
    c[s[top--]] = col;
    vis[x] = 0;
  }
}
void fuck() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", a + i, b + i);
    add(a[i], b[i]);
  }
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) xxx(i);
  if (col == 1) {
    puts("No");
    return;
  }
  for (int i = 1; i <= m; i++)
    if (c[a[i]] != c[b[i]]) k[c[a[i]]]++;
  for (int i = 1; i <= col; i++)
    if (!k[i]) {
      rt = i;
      break;
    }
  for (int i = 1; i <= n; i++) ans += c[i] == rt;
  printf("Yes\n%d %d\n", ans, n - ans);
  for (int i = 1; i <= n; i++)
    if (c[i] == rt) printf("%d ", i);
  puts("");
  for (int i = 1; i <= n; i++)
    if (c[i] != rt) printf("%d ", i);
  puts("");
}
void X() {
  ans = tot = top = col = cnt = 0;
  for (int i = 1; i <= n; i++)
    s[i] = Last[i] = dfn[i] = low[i] = vis[i] = c[i] = k[i] = 0;
}
int main() {
  for (scanf("%d", &t); t--; fuck(), X())
    ;
}
