#include <bits/stdc++.h>
using namespace std;
vector<int> g[1000001];
bool used1[1000001];
void dfs1(int v) {
  used1[v] = true;
  for (auto to : g[v]) {
    if (used1[to]) continue;
    dfs1(to);
  }
}
vector<int> r[1000001];
bool used2[1000001];
void dfs2(int v) {
  used2[v] = true;
  for (auto to : r[v]) {
    if (used2[to]) continue;
    dfs2(to);
  }
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    g[i].clear(), r[i].clear(), used1[i] = used2[i] = false;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    if (a == b) continue;
    g[a].push_back(b);
    r[b].push_back(a);
  }
  dfs1(1);
  int cnt1 = 0;
  for (int i = 1; i <= n; i++) {
    if (!used1[i]) cnt1++;
  }
  if (cnt1 > 0) {
    cout << "Yes\n";
    cout << n - cnt1 << " " << cnt1 << '\n';
    for (int i = 1; i <= n; i++)
      if (used1[i]) cout << i << " ";
    cout << '\n';
    for (int i = 1; i <= n; i++)
      if (!used1[i]) cout << i << " ";
    cout << '\n';
    return;
  }
  dfs2(1);
  int cnt2 = 0;
  for (int i = 1; i <= n; i++) {
    if (!used2[i]) cnt2++;
  }
  if (cnt2 > 0) {
    cout << "Yes\n";
    cout << cnt2 << " " << n - cnt2 << '\n';
    for (int i = 1; i <= n; i++)
      if (!used2[i]) cout << i << " ";
    cout << '\n';
    for (int i = 1; i <= n; i++)
      if (used2[i]) cout << i << " ";
    cout << '\n';
    return;
  }
  cout << "No\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}
