#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2")
#pragma GCC optimize("unroll-loops")
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void print(vector<int> &a) {
  cout << "Yes\n";
  vector<int> ans1, ans2;
  int n = (int)a.size();
  for (int i = 0; i < n; i++) {
    if (a[i])
      ans1.push_back(i);
    else
      ans2.push_back(i);
  }
  cout << (int)ans1.size() << ' ' << (int)ans2.size() << '\n';
  for (auto x : ans1) cout << x + 1 << ' ';
  cout << '\n';
  for (auto x : ans2) cout << x + 1 << ' ';
  cout << '\n';
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n), rg(n);
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    v--;
    u--;
    if (v == u) continue;
    g[v].push_back(u);
    rg[u].push_back(v);
  }
  queue<int> q;
  vector<int> used(n);
  q.push(0);
  used[0] = 1;
  while ((int)q.size()) {
    int v = q.front();
    q.pop();
    for (auto u : g[v]) {
      if (!used[u]) {
        used[u] = 1;
        q.push(u);
      }
    }
  }
  if (count(used.begin(), used.end(), 0) != 0) {
    print(used);
    return;
  }
  fill(used.begin(), used.end(), 0);
  q.push(0);
  used[0] = 1;
  while ((int)q.size()) {
    int v = q.front();
    q.pop();
    for (auto u : rg[v]) {
      if (!used[u]) {
        used[u] = 1;
        q.push(u);
      }
    }
  }
  for (auto &x : used) x = x ^ 1;
  if (count(used.begin(), used.end(), 1) != 0) {
    print(used);
    return;
  }
  cout << "No\n";
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    solve();
  }
}
