#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
vector<vector<int>> g, gr, a;
vector<int> comp, used;
void dfs(int u, vector<int> &topsort) {
  used[u] = 1;
  for (auto v : g[u])
    if (!used[v]) {
      dfs(v, topsort);
    }
  topsort.push_back(u);
}
void init(int u, int cur) {
  comp[u] = cur;
  for (auto v : gr[u]) {
    if (comp[v] == -1) {
      init(v, cur);
    }
  }
}
void PUNKS_NOT_DEAD() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    gr.clear(), g.clear(), a.clear(), comp.clear(), used.clear();
    gr.resize(n), g.resize(n), a.resize(n), comp.resize(n, -1), used.resize(n);
    while (m--) {
      int u, v;
      cin >> u >> v, u--, v--;
      g[u].push_back(v), gr[v].push_back(u);
    }
    vector<int> topsort;
    int bands = 0;
    for (int i = 0; i < n; i++) {
      if (!used[i]) {
        bands++;
        if (bands == 2) {
          break;
        }
        dfs(i, topsort);
      }
    }
    int z = 0;
    reverse(topsort.begin(), topsort.end());
    for (auto i : topsort)
      if (comp[i] == -1) init(i, z++);
    vector<int> cnt(z);
    for (int i = 0; i < n; i++)
      for (auto v : g[i]) {
        if (comp[v] != -1 && comp[i] != -1 && comp[i] != comp[v]) {
          cnt[comp[v]] = 1;
        }
      }
    int f_cats = -1;
    for (int i = 0; i < z; i++)
      if (cnt[i] == 0) f_cats = i;
    vector<int> people, cats;
    if (bands == 2) {
      for (int i = 0; i < n; i++) {
        if (used[i])
          people.push_back(i);
        else
          cats.push_back(i);
      }
    } else if (f_cats != -1) {
      for (int i = 0; i < n; i++) {
        if (comp[i] == f_cats)
          cats.push_back(i);
        else
          people.push_back(i);
      }
    }
    if (people.size() && cats.size()) {
      cout << "Yes\n";
      cout << people.size() << ' ' << cats.size() << "\n";
      for (auto v : people) cout << v + 1 << ' ';
      cout << "\n";
      for (auto v : cats) cout << v + 1 << ' ';
    } else {
      cout << "No";
    }
    cout << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0), PUNKS_NOT_DEAD();
}
