#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> g[1000005], r[1000005], topsort, scc[1000005], conn[1000005];
long long vis[1000005], color[1000005];
long long compno = 0;
void dfs(long long x) {
  vis[x] = 1;
  for (auto &it : g[x])
    if (vis[it] == 0) dfs(it);
  topsort.push_back(x);
}
void dfs1(long long x) {
  vis[x] = 1;
  color[x] = compno;
  conn[compno].push_back(x);
  for (auto &it : r[x])
    if (!vis[it]) dfs1(it);
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (long long i = 0; i <= n; ++i) {
      g[i].clear();
      r[i].clear();
      color[i] = 0;
      scc[i].clear();
      conn[i].clear();
      vis[i] = 0;
    }
    topsort.clear();
    compno = 0;
    vector<pair<long long, long long> > edges;
    for (long long i = 1; i <= m; ++i) {
      long long x, y;
      cin >> x >> y;
      if (x == y) continue;
      edges.push_back({x, y});
      g[x].push_back(y);
      r[y].push_back(x);
    }
    for (long long i = 1; i <= n; ++i)
      if (vis[i] == 0) dfs(i);
    for (long long i = 1; i <= n; ++i) vis[i] = 0;
    while (!topsort.empty()) {
      long long x = topsort.back();
      topsort.pop_back();
      if (!vis[x]) {
        ++compno;
        dfs1(x);
      }
    }
    if (compno < 2) {
      cout << "No\n";
      continue;
    }
    for (auto &it : edges) {
      long long x = it.first;
      long long y = it.second;
      if (color[x] != color[y]) scc[color[x]].push_back(color[y]);
    }
    long long jury = -1;
    vector<long long> j, c;
    for (long long i = 1; i <= compno; ++i)
      if (scc[i].size() == 0) jury = i;
    if (jury == -1) {
      cout << "No\n";
      continue;
    }
    for (long long i = 1; i <= compno; ++i)
      if (i == jury)
        for (auto &it : conn[i]) j.push_back(it);
      else
        for (auto &it : conn[i]) c.push_back(it);
    cout << "Yes\n";
    cout << j.size() << " " << c.size() << "\n";
    for (auto &it : j) cout << it << " ";
    cout << "\n";
    for (auto &it : c) cout << it << " ";
    cout << "\n";
  }
  return 0;
}
