#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
vector<vector<int>> adjlist;
int counter, sccCounter;
vector<bool> inStack;
vector<vector<int>> sccs;
vector<int> d, low, idx, s;
void visit(int v) {
  d[v] = low[v] = counter++;
  s.push_back(v);
  inStack[v] = true;
  for (auto u : adjlist[v]) {
    if (d[u] < 0) {
      visit(u);
      low[v] = min(low[v], low[u]);
    } else if (inStack[u]) {
      low[v] = min(low[v], low[u]);
    }
  }
  if (d[v] == low[v]) {
    sccs.push_back({});
    int u;
    do {
      u = s.back();
      s.pop_back();
      inStack[u] = false;
      idx[u] = sccCounter;
      sccs[sccCounter].push_back(u);
    } while (u != v);
    sccCounter++;
  }
}
void scc() {
  inStack.assign((int)(adjlist).size(), false);
  d.assign((int)(adjlist).size(), -1);
  low.assign((int)(adjlist).size(), -1);
  idx.assign((int)(adjlist).size(), -1);
  s.clear();
  sccs.clear();
  counter = sccCounter = 0;
  for (int i = 0; i < (int)(adjlist).size(); i++) {
    if (d[i] < 0) visit(i);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll t;
  cin >> t;
  for (ll i = 0; i < t; i++) {
    ll n, m;
    cin >> n >> m;
    adjlist.assign(n, {});
    map<pair<ll, ll>, ll> c;
    for (ll i = 0; i < m; i++) {
      ll a, b;
      cin >> a >> b;
      a--;
      b--;
      if (a != b) adjlist[a].push_back(b);
    }
    scc();
    if ((int)(sccs).size() <= 1) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
      reverse(begin(sccs), end(sccs));
      cout << n - (int)(sccs[0]).size() << " " << (int)(sccs[0]).size() << endl;
      for (ll i = 1; i < (int)(sccs).size(); i++) {
        for (ll x : sccs[i]) {
          cout << x + 1 << " ";
        }
      }
      cout << endl;
      for (ll x : sccs[0]) {
        cout << x + 1 << " ";
      }
      cout << endl;
    }
  }
}
