#include <bits/stdc++.h>
using namespace std;
struct SCC {
  int* idx;
  int* low;
  bool* active;
  vector<int>* v;
  vector<int> temp;
  vector<vector<int>> sccs;
  SCC(int n) {
    idx = new int[n];
    low = new int[n];
    active = new bool[n];
    v = new vector<int>[n];
    for (int i = 0; i < n; i++) {
      idx[i] = 0;
      low[i] = 0;
      active[i] = 0;
    }
  }
  void dfs(int x, int _root, int& t) {
    low[x] = idx[x] = ++t;
    active[x] = true;
    temp.push_back(x);
    for (int i = 0; i < v[x].size(); ++i) {
      if (!idx[v[x][i]]) {
        dfs(v[x][i], _root, t);
        low[x] = min(low[x], low[v[x][i]]);
      } else {
        if (active[v[x][i]] && idx[v[x][i]] < idx[x]) {
          low[x] = min(low[x], idx[v[x][i]]);
        }
      }
    }
    if (low[x] == idx[x]) {
      sccs.push_back({});
      while (true) {
        sccs.back().push_back(temp.back());
        active[temp.back()] = false;
        if (temp.back() == x) {
          temp.pop_back();
          break;
        } else
          temp.pop_back();
      }
    }
  }
};
int32_t main() {
  cin.tie(NULL);
  cin.sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int nn = n;
    n *= 2;
    SCC scc(n);
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      scc.v[a].push_back(b + nn);
    }
    for (int i = 0; i < nn; i++) {
      scc.v[i + nn].push_back(i);
    }
    int t = 0;
    for (int i = 0; i < n; ++i) {
      if (!scc.idx[i]) scc.dfs(i, i, t);
    }
    vector<int> ans(n);
    for (int i = 0; i < scc.sccs.size(); ++i) {
      for (auto x : scc.sccs[i]) {
        ans[x] = i;
      }
    }
    if (scc.sccs.size() == 1) {
      cout << "No\n";
      continue;
    }
    int resp = -1;
    for (int i = 0; i < scc.sccs.size(); i++) {
      bool dm = false;
      for (auto k : scc.sccs[i]) {
        for (auto meligo : scc.v[k]) {
          if (ans[meligo] != i) {
            dm = true;
            break;
          }
        }
        if (dm) break;
      }
      if (!dm) {
        resp = i;
        break;
      }
    }
    if (resp == -1) {
      cout << "No\n";
      continue;
    }
    vector<int> gatos;
    vector<bool> visto(nn, false);
    for (auto k : scc.sccs[resp]) {
      if (k >= nn) {
        gatos.push_back(k);
        visto[k - nn] = true;
      }
    }
    cout << "Yes\n";
    cout << gatos.size() << " " << nn - gatos.size() << endl;
    for (auto k : gatos) {
      cout << k - nn + 1 << " ";
    }
    cout << '\n';
    for (int i = 0; i < nn; i++) {
      if (!visto[i]) {
        cout << i + 1 << " ";
      }
    }
    cout << '\n';
  }
}
