#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, m;
stack<int> s;
int T, num;
int col[N], dfn[N], low[N];
std::vector<int> scc[N], g[N];
void Tarjan(int u) {
  dfn[u] = low[u] = ++T;
  s.push(u);
  for (auto v : g[u]) {
    if (!dfn[v]) {
      Tarjan(v);
      low[u] = min(low[u], low[v]);
    } else if (!col[v]) {
      low[u] = min(low[u], dfn[v]);
    }
  }
  if (low[u] == dfn[u]) {
    num++;
    int now;
    do {
      now = s.top();
      s.pop();
      col[now] = num;
      scc[num].push_back(now);
    } while (!s.empty() && now != u);
  }
}
void init() {
  for (int i = 1; i <= n; i++) {
    scc[i].clear();
    g[i].clear();
    col[i] = dfn[i] = 0;
  }
  num = T = 0;
}
void run() {
  cin >> n >> m;
  init();
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) {
    if (!dfn[i]) {
      Tarjan(i);
    }
  }
  if (n == 1 || num == 1) {
    cout << "No" << '\n';
    return;
  }
  std::vector<int> ans[2];
  ans[0] = scc[1];
  for (int i = 2; i <= num; i++) {
    for (auto it : scc[i]) ans[1].push_back(it);
  }
  cout << "Yes" << '\n';
  cout << (int)(ans[0]).size() << ' ' << (int)(ans[1]).size() << '\n';
  for (auto it : ans[0]) cout << it << ' ';
  cout << '\n';
  for (auto it : ans[1]) cout << it << ' ';
  cout << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(20);
  int T;
  cin >> T;
  while (T--) run();
  return 0;
}
