#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 5;
struct Tarjan {
  int n, id, scc, low[maxn], dfn[maxn], bl[maxn], dg_in[maxn];
  stack<int> sta;
  vector<int> g[maxn], gn[maxn], gnv[maxn];
  bool in[maxn], vis[maxn];
  void init(int n) {
    this->n = n;
    id = scc = 0;
    for (int i = 1; i <= n; i++) {
      g[i].clear();
      gn[i].clear();
      gnv[i].clear();
      dfn[i] = low[i] = in[i] = bl[i] = vis[i] = dg_in[i] = 0;
    }
    while (!sta.empty()) sta.pop();
  }
  void add(int u, int v) { g[u].push_back(v); }
  void add_new(int u, int v) {
    dg_in[v]++;
    gn[u].push_back(v);
    gnv[v].push_back(u);
  }
  void tj(int u) {
    low[u] = dfn[u] = ++id;
    in[u] = 1;
    sta.push(u);
    for (auto v : g[u]) {
      if (!dfn[v])
        tj(v), low[u] = min(low[u], low[v]);
      else if (in[v])
        low[u] = min(low[u], dfn[v]);
    }
    if (dfn[u] == low[u]) {
      scc++;
      int x = 0;
      while (x != u) {
        x = sta.top();
        sta.pop();
        bl[x] = scc, in[x] = 0;
      }
    }
  }
  void work() {
    for (int i = 1; i <= n; i++) {
      if (!dfn[i]) tj(i);
    }
  }
  void rebuild() {
    for (int u = 1; u <= n; u++) {
      for (auto v : g[u]) {
        if (bl[u] != bl[v]) add_new(bl[v], bl[u]);
      }
    }
  }
} tj;
vector<int> jury, cont;
queue<int> q;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    tj.init(n);
    int u, v;
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &u, &v);
      if (u != v) tj.add(u, v);
    }
    tj.work();
    tj.rebuild();
    if (tj.scc == 1) {
      cout << "No" << endl;
      continue;
    }
    jury.clear();
    cont.clear();
    for (int i = 1; i <= n; i++) {
      if (tj.bl[i] == 1) {
        jury.push_back(i);
      } else {
        cont.push_back(i);
      }
    }
    cout << "Yes" << endl;
    printf("%d %d\n", jury.size(), cont.size());
    for (int i = 0; i < jury.size(); i++) {
      if (i == jury.size() - 1)
        printf("%d\n", jury[i]);
      else
        printf("%d ", jury[i]);
    }
    for (int i = 0; i < cont.size(); i++) {
      if (i == cont.size() - 1)
        printf("%d\n", cont[i]);
      else
        printf("%d ", cont[i]);
    }
  }
  return 0;
}
