#include <bits/stdc++.h>
using namespace std;
const string __sep = "\n";
void dfs1(vector<vector<int>>& g, int v, vector<int>& order,
          vector<int>& used) {
  used[v] = true;
  for (auto next : g[v]) {
    if (!used[next]) dfs1(g, next, order, used);
  }
  order.push_back(v);
}
void dfs2(vector<vector<int>>& gt, int v, vector<int>& cur_comp,
          vector<int>& used) {
  used[v] = true;
  cur_comp.push_back(v);
  for (auto next : gt[v]) {
    if (!used[next]) dfs2(gt, next, cur_comp, used);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t > 0) {
    --t;
    int n, m;
    cin >> n >> m;
    vector<vector<int>> gr(n);
    vector<vector<int>> grt(n);
    for (int i = 0; i < m; ++i) {
      int x, y;
      cin >> x >> y;
      if (x == y) continue;
      --x;
      --y;
      gr[x].push_back(y);
      grt[y].push_back(x);
    }
    vector<int> was(n, 0);
    vector<int> order;
    for (int x = 0; x < n; ++x) {
      if (was[x]) continue;
      dfs1(gr, x, order, was);
    }
    was.assign(n, 0);
    reverse(order.begin(), order.end());
    vector<int> cur_comp;
    bool found = false;
    for (int x : order) {
      dfs2(grt, x, cur_comp, was);
      if (cur_comp.size() == n) continue;
      unordered_set<int> ans(cur_comp.begin(), cur_comp.end());
      for (int elem : cur_comp) {
        for (auto next : gr[elem]) ans.insert(next);
      }
      if (ans.size() == cur_comp.size()) {
        cout << "Yes\n"
             << cur_comp.size() << " " << (n - cur_comp.size()) << "\n";
        for (auto an : cur_comp) {
          cout << (an + 1) << " ";
        }
        cout << "\n";
        for (int i = 0; i < n; ++i)
          if (ans.find(i) == ans.end()) cout << (i + 1) << " ";
        cout << "\n";
        found = true;
        break;
      }
      cur_comp.clear();
    }
    if (!found) cout << "No\n";
  }
  return 0;
}
