#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100, M = 1e6 + 100;
struct Edge {
  int v, nxt;
} e[M << 1];
int timestamp, tp, tot, low[N], dfn[N], stk[N], head[N], scc_cnt;
bool in_stk[N], mark[N];
int n, m, T;
vector<int> vec;
void AddEdge(int u, int v) {
  e[++tot].v = v;
  e[tot].nxt = head[u];
  head[u] = tot;
}
void tarjan(int u) {
  dfn[u] = low[u] = ++timestamp;
  stk[++tp] = u;
  in_stk[u] = true;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (!dfn[v]) {
      tarjan(v);
      low[u] = min(low[u], low[v]);
    } else if (in_stk[v]) {
      low[u] = min(low[u], dfn[v]);
    }
  }
  if (low[u] == dfn[u]) {
    int y;
    scc_cnt++;
    do {
      if (scc_cnt > 1) break;
      y = stk[tp--];
      in_stk[y] = false;
      vec.push_back(y);
      mark[y] = true;
    } while (u != y);
  }
}
int main() {
  scanf("%d", &T);
  while (T--) {
    timestamp = tp = tot = scc_cnt = 0;
    for (int i = 1; i <= n; i++) {
      mark[i] = head[i] = in_stk[i] = dfn[i] = 0;
    }
    vec.clear();
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      if (u == v) continue;
      AddEdge(u, v);
    }
    for (int i = 1; i <= n; i++)
      if (!dfn[i]) tarjan(i);
    if (scc_cnt == 1)
      puts("No");
    else {
      puts("Yes");
      int t = (int)vec.size();
      printf("%d %d", t, n - t);
      puts("");
      for (int i = 0; i < t; i++) printf("%d ", vec[i]);
      puts("");
      for (int i = 1; i <= n; i++)
        if (!mark[i]) printf("%d ", i);
      puts("");
    }
  }
  return 0;
}
