#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, nxt;
} e[2000005 << 1];
int head[2000005], tot, n, m;
int c[2000005], out[2000005], cnt;
int ind, dfn[2000005], low[2000005], stk[2000005], top, ins[2000005];
void tarjan(int x) {
  dfn[x] = low[x] = ++ind;
  stk[++top] = x;
  ins[x] = 1;
  for (int i = head[x]; i != -1; i = e[i].nxt) {
    int y = e[i].to;
    if (!dfn[y]) {
      tarjan(y);
      low[x] = min(low[x], low[y]);
    } else if (ins[y])
      low[x] = min(low[x], dfn[y]);
  }
  if (dfn[x] == low[x]) {
    cnt++;
    int y;
    do {
      y = stk[top--];
      ins[y] = 0;
      c[y] = cnt;
    } while (x != y);
  }
}
void init() {
  cnt = tot = ind = 0;
  for (int i = 0; i <= 2 * n; i++)
    low[i] = dfn[i] = ins[i] = out[i] = c[i] = 0, head[i] = -1;
}
void add(int u, int v) {
  e[tot].to = v;
  e[tot].nxt = head[u];
  head[u] = tot++;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    init();
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      if (u != v) add(u, v);
    }
    for (int i = 1; i <= n; i++)
      if (!dfn[i]) tarjan(i);
    for (int u = 1; u <= n; u++)
      for (int i = head[u]; i != -1; i = e[i].nxt) {
        int v = e[i].to;
        if (c[u] != c[v]) out[c[u]]++;
      }
    int ans = 0;
    for (int i = 1; i <= cnt; i++)
      if (out[i] == 0) {
        ans = i;
        break;
      }
    if (ans == 0 || cnt == 1) {
      puts("No");
      continue;
    }
    puts("Yes");
    int cnta = 0, cntb = 0;
    for (int i = 1; i <= n; i++)
      if (c[i] == ans)
        cnta++;
      else
        cntb++;
    cout << cnta << " " << cntb << '\n';
    for (int i = 1; i <= n; i++)
      if (c[i] == ans) cout << i << " ";
    puts("");
    for (int i = 1; i <= n; i++)
      if (c[i] != ans) cout << i << " ";
    puts("");
  }
}
