#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
vector<vector<int> > g, G;
vector<int> low, dis, vis, S, comp;
int cont, scc;
void dfs(int u) {
  dis[u] = cont;
  low[u] = cont++;
  S.push_back(u);
  vis[u] = 1;
  for (auto v : g[u]) {
    if (!dis[v]) dfs(v);
    if (vis[v]) low[u] = min(low[u], low[v]);
  }
  if (low[u] == dis[u]) {
    scc++;
    while (1) {
      int v = S.back();
      S.pop_back();
      vis[v] = 0;
      comp[v] = scc - 1;
      if (u == v) break;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1, n, m;
  cin >> T;
  while (T--) {
    cin >> n >> m;
    g.clear();
    g.assign(2 * n, vector<int>());
    for (int i = 0; i < m; ++i) {
      int u, v;
      cin >> u >> v;
      u--;
      v--;
      if (u != v)
        g[u].push_back(v + n);
      else
        g[v + n].push_back(u);
    }
    low.assign(2 * n + 1, 0);
    dis.assign(2 * n + 1, 0);
    vis.assign(2 * n + 1, 0);
    comp.assign(2 * n + 1, 0);
    cont = 1;
    scc = 0;
    for (int k = 0; k < 2 * n; ++k) {
      if (!dis[k]) dfs(k);
    }
    if (scc == 1 || n == 1) {
      cout << "No\n";
      continue;
    }
    cout << "Yes\n";
    vector<int> inDegree(scc, 0);
    for (int j = 0; j < 2 * n; ++j) {
      for (int u : g[j]) {
        if (comp[u] == comp[j]) continue;
        inDegree[comp[u]]++;
      }
    }
    int source = 0;
    for (int l = n; l < 2 * n; ++l) {
      if (inDegree[comp[l]] == 0) {
        source = comp[l];
      }
    }
    int cnt = 0;
    for (int i1 = 0; i1 < 2 * n; ++i1) {
      if (comp[i1] == source && i1 >= n) cnt++;
    }
    cout << n - cnt << " " << cnt << "\n";
    for (int j1 = 0; j1 < n; ++j1) {
      if (comp[j1 + n] == source)
        cnt++;
      else
        cout << j1 + 1 << " ";
    }
    cout << "\n";
    for (int j1 = n; j1 < 2 * n; ++j1) {
      if (comp[j1] == source) cout << j1 - n + 1 << " ";
    }
    cout << "\n";
  }
}
