#include <bits/stdc++.h>
using namespace std;
void dfs(int node, vector<vector<int>> &g, vector<int> &seen, vector<int> &st) {
  seen[node] = 1;
  for (auto v : g[node]) {
    if (seen[v]) continue;
    dfs(v, g, seen, st);
  }
  st.push_back(node);
}
void dfs2(int node, vector<vector<int>> &g, vector<int> &seen, int c) {
  seen[node] = c;
  for (auto v : g[node]) {
    if (seen[v]) continue;
    dfs2(v, g, seen, c);
  }
}
vector<int> solve(vector<vector<int>> &g) {
  int n = g.size();
  vector<vector<int>> h(n);
  for (int a = 0; a < n; a += 1)
    for (auto b : g[a]) h[b].push_back(a);
  vector<int> seen(n, 0);
  vector<int> st;
  for (int i = 0; i < n; i += 1)
    if (not seen[i]) {
      dfs(i, h, seen, st);
    }
  seen = vector<int>(n, 0);
  int c = 0;
  for (int i = n - 1; i >= 0; i -= 1) {
    if (seen[st[i]] == 0) {
      c += 1;
      dfs2(st[i], g, seen, c);
    }
  }
  if (c == 1) {
    return vector<int>();
  }
  vector<int> ans(n, 0);
  for (int i = 0; i < n; i += 1) {
    if (seen[i] == 1) {
      ans[i] = 1;
    }
  }
  return ans;
}
int main() {
  ios_base ::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i += 1) {
      int a, b;
      cin >> a >> b;
      a -= 1;
      b -= 1;
      if (a != b) g[a].push_back(b);
    }
    auto res = solve(g);
    if (res.empty()) {
      cout << "No\n";
    } else {
      cout << "Yes\n";
      vector<int> a, b;
      for (int i = 0; i < n; i += 1)
        if (res[i] == 1) a.push_back(i);
      for (int i = 0; i < n; i += 1)
        if (res[i] == 0) b.push_back(i);
      cout << a.size() << " " << b.size() << "\n";
      for (auto val : a) cout << val + 1 << " ";
      cout << "\n";
      for (auto val : b) cout << val + 1 << " ";
      cout << "\n";
    }
  }
}
