#include <bits/stdc++.h>
using namespace std;
int t, n, m;
vector<int> adj[2000005];
vector<int> revadj[2000005];
bool vis[2000005];
int comp[2000005];
stack<int> s;
vector<int> ans, ans1;
void dfs(int i) {
  vis[i] = 1;
  for (auto j : adj[i])
    if (!vis[j]) dfs(j);
  s.push(i);
}
void revdfs(int i, int c) {
  comp[i] = c;
  vis[i] = 1;
  for (auto j : revadj[i])
    if (!vis[j]) revdfs(j, c);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 1; i <= 2 * n; i++) {
      adj[i].clear();
      revadj[i].clear();
      comp[i] = i;
    }
    for (int i = 1; i <= m; i++) {
      int x, y;
      cin >> x >> y;
      adj[x].push_back(n + y);
      revadj[n + y].push_back(x);
    }
    for (int i = 1; i <= n; i++) {
      adj[n + i].push_back(i);
      revadj[i].push_back(n + i);
    }
    for (int i = 1; i <= 2 * n; i++) vis[i] = 0;
    for (int i = 1; i <= 2 * n; i++)
      if (!vis[i]) dfs(i);
    for (int i = 1; i <= 2 * n; i++) vis[i] = 0;
    while (s.size()) {
      int x = s.top();
      s.pop();
      if (vis[x]) continue;
      revdfs(x, x);
    }
    int cnt = 0;
    for (int i = 1; i <= 2 * n; i++)
      if (comp[i] == i) cnt++;
    if (cnt == 1) {
      cout << "No" << '\n';
      continue;
    }
    for (int i = 1; i <= 2 * n; i++) vis[i] = 0;
    for (int i = 1; i <= 2 * n; i++)
      for (auto j : adj[i])
        if (comp[j] != comp[i]) vis[comp[i]] = 1;
    int k = 0;
    for (int i = 1; i <= 2 * n; i++)
      if (comp[i] == i && !vis[i]) k = i;
    ans.clear();
    ans1.clear();
    for (int i = 1; i <= n; i++)
      if (comp[i] == k) ans.push_back(i);
    for (int i = n + 1; i <= 2 * n; i++)
      if (comp[i] != k) ans1.push_back(i - n);
    cout << "Yes" << '\n';
    cout << ans.size() << " " << ans1.size() << '\n';
    for (auto j : ans) cout << j << " ";
    cout << '\n';
    for (auto j : ans1) cout << j << " ";
    cout << '\n';
  }
  return 0;
}
