#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long MAXN = 1123456;
const long long N = 2e6;
const long long inf = 3e18;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
template <typename T>
void vout(T s) {
  cout << s << endl;
  exit(0);
}
vector<long long> g[MAXN], g1[MAXN];
int Max;
bool f[MAXN], f1[MAXN];
vector<long long> order;
void dfs(long long x) {
  if (f[x]) return;
  f[x] = 1;
  for (auto to : g[x]) dfs(to);
  Max = x;
}
void dfs1(long long x) {
  if (f1[x]) return;
  f1[x] = 1;
  for (auto to : g1[x]) dfs1(to);
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      g[i].clear(), g1[i].clear();
      f[i] = f1[i] = 0;
    }
    int m;
    cin >> m;
    while (m--) {
      int a, b;
      cin >> a >> b;
      g[a].push_back(b);
      g1[b].push_back(a);
    }
    for (int i = 1; i <= n; i++) dfs(i);
    dfs1(Max);
    if (*min_element(f1 + 1, f1 + n + 1) == 0) {
      vector<int> res_cats, res_people;
      for (int i = 1; i <= n; i++)
        if (f1[i])
          res_cats.push_back(i);
        else
          res_people.push_back(i);
      cout << "Yes\n";
      cout << (int)res_people.size() << " " << (int)res_cats.size() << "\n";
      for (auto i : res_people) cout << i << " ";
      cout << "\n";
      for (auto i : res_cats) cout << i << " ";
      cout << "\n";
    } else
      cout << "No\n";
  }
  return 0;
}
