#include <bits/stdc++.h>
using namespace std;
struct Debug {
  int cnt = 0;
  bool on = false;
  char debug[10] = "debug";
  template <class T>
  Debug& operator<<(const T& v) {
    if (on && cnt++ == 0) cerr << "debug: ";
    if (on) cerr << v << ' ';
    return *this;
  }
  Debug& operator<<(ostream& (*pManip)(ostream&)) {
    if (on) cerr << (*pManip);
    cnt = 0;
    return *this;
  }
} debug;
const int MAXN = 1e6 + 10;
struct SCC {
  vector<int>* graph;
  vector<int> rev_graph[MAXN], scc_graph[MAXN], scc_nodes[MAXN];
  int tin[MAXN], tout[MAXN], order[MAXN], scc[MAXN];
  int n, t, scc_cnt;
  void set(int _n, vector<int>* _graph) {
    n = _n;
    graph = _graph;
  }
  void dfs(int i) {
    tin[i] = t++;
    for (int j : graph[i])
      if (!tin[j]) dfs(j);
    tout[i] = t++;
  }
  void rdfs(int i, int num) {
    scc[i] = num;
    for (int j : rev_graph[i])
      if (!scc[j]) rdfs(j, num);
  }
  void cal() {
    t = 1;
    fill(tin, tin + n + 1, 0);
    fill(tout, tout + n + 1, 0);
    for (int i = 1; i <= n; i++) {
      if (!tout[i]) dfs(i);
    }
    iota(order, order + n, 1);
    sort(order, order + n,
         [&](const int& x, const int& y) { return tout[x] > tout[y]; });
    for (int i = 1; i <= n; i++) rev_graph[i].clear();
    for (int i = 1; i <= n; i++) {
      for (int j : graph[i]) {
        rev_graph[j].push_back(i);
      }
    }
    fill(scc, scc + n + 1, 0);
    scc_cnt = 0;
    for (int i = 0; i < n; i++) {
      if (!scc[order[i]]) {
        scc_cnt++;
        rdfs(order[i], scc_cnt);
      }
    }
    for (int i = 1; i <= n; i++) scc_nodes[i].clear();
    for (int i = 1; i <= n; i++) scc_nodes[scc[i]].push_back(i);
    for (int i = 1; i <= scc_cnt; i++) scc_graph[i].clear();
    for (int i = 1; i <= n; i++) {
      for (int j : graph[i]) {
        if (scc[i] != scc[j]) {
          scc_graph[scc[i]].push_back(scc[j]);
        }
      }
    }
    for (int i = 1; i <= scc_cnt; i++) {
      auto& cur = scc_graph[i];
      sort(cur.begin(), cur.end());
      cur.erase(unique(cur.begin(), cur.end()), cur.end());
    }
  }
};
vector<int> graph[MAXN];
int n, m;
SCC scc;
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  if (argc > 1 && !strcmp(argv[1], debug.debug)) debug.on = true;
  int q;
  cin >> q;
  for (int tt = 0; tt < q; tt++) {
    cin >> n >> m;
    int u, v;
    for (int i = 0; i < m; i++) {
      cin >> u >> v;
      if (u == v) continue;
      graph[u].push_back(v);
    }
    scc.set(n, graph);
    scc.cal();
    if (scc.scc_cnt == 1)
      cout << "No" << endl;
    else {
      cout << "Yes" << endl;
      cout << n - scc.scc_nodes[1].size() << ' ' << scc.scc_nodes[1].size()
           << endl;
      for (int i = 1; i <= n; i++)
        if (scc.scc[i] != 1) cout << i << ' ';
      cout << endl;
      for (int i = 1; i <= n; i++)
        if (scc.scc[i] == 1) cout << i << ' ';
      cout << endl;
    }
    for (int i = 1; i <= n; i++) graph[i].clear();
  }
  return 0;
}
