#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
  return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
  os << '[';
  for (unsigned long long i = 0; i < a.size(); i++)
    os << a[i] << (i < a.size() - 1 ? ", " : "");
  os << ']';
  return os;
}
vector<vector<long long> > a;
long long n, m;
struct DirectedDfs {
  vector<long long> num, low, in, S;
  long long counter;
  vector<vector<long long> > scc;
  DirectedDfs() : num(n + 5, -1), low(n + 5, 0), in(n + 5, 0), counter(0) {
    for (long long i = (1); i <= (n); i++)
      if (num[i] == -1) dfs(i);
  }
  void dfs(long long u) {
    low[u] = num[u] = counter++;
    S.push_back(u);
    in[u] = 1;
    for (auto v : a[u]) {
      if (num[v] == -1) dfs(v);
      if (in[v]) low[u] = min(low[u], low[v]);
    }
    if (low[u] == num[u]) {
      scc.push_back(vector<long long>());
      while (1) {
        long long v = S.back();
        S.pop_back();
        in[v] = 0;
        scc.back().push_back(v);
        if (u == v) break;
      }
    }
  }
};
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    cin >> n >> m;
    a.assign(n + 1, vector<long long>());
    for (long long i = (1); i <= (m); i++) {
      long long u, v;
      cin >> u >> v;
      if (u != v) a[u].push_back(v);
    }
    DirectedDfs tree;
    if (tree.scc.size() == 1) {
      cout << "No" << '\n';
      continue;
    }
    vector<long long> id(n + 1, 0);
    for (long long i = (0); i <= (tree.scc.size() - 1); i++) {
      for (auto &v : tree.scc[i]) id[v] = i;
    }
    long long wh = -1;
    for (long long i = (0); i <= (tree.scc.size() - 1); i++) {
      bool ok = true;
      for (auto &u : tree.scc[i]) {
        for (auto &v : a[u]) {
          if (id[v] != id[u]) {
            ok = false;
            break;
          }
        }
        if (!ok) break;
      }
      if (ok) {
        wh = i;
        break;
      }
    }
    if (wh == -1) {
      cout << "No" << '\n';
      continue;
    }
    vector<bool> mark(n + 1, 0);
    long long cnt = tree.scc[wh].size();
    for (auto &u : tree.scc[wh]) mark[u] = true;
    cout << "Yes" << '\n';
    cout << cnt << ' ' << n - cnt << '\n';
    for (long long i = (1); i <= (n); i++)
      if (mark[i]) cout << i << ' ';
    cout << '\n';
    for (long long i = (1); i <= (n); i++)
      if (!mark[i]) cout << i << ' ';
    cout << '\n';
  }
}
