#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
const int INF = 1e9;
int t, n, m, cpm, cnt, degout[MAXN], tp[MAXN], num[MAXN], low[MAXN];
vector<int> E[MAXN], r1, r2;
stack<int> s;
void reset() {
  cpm = 0;
  cnt = 0;
  for (long long i = 1; i <= n; i++) {
    E[i].clear();
    num[i] = 0;
    low[i] = 0;
    degout[i] = 0;
    tp[i] = 0;
  }
  while (s.size()) s.pop();
  r1.clear();
  r2.clear();
}
void visit(int u) {
  s.push(u);
  num[u] = low[u] = ++cnt;
  for (auto v : E[u]) {
    if (!num[v]) {
      visit(v);
      low[u] = min(low[u], low[v]);
    } else {
      low[u] = min(low[u], num[v]);
    }
  }
  if (low[u] == num[u]) {
    cpm++;
    int v;
    do {
      v = s.top();
      s.pop();
      num[v] = INF;
      low[v] = INF;
      tp[v] = cpm;
    } while (v != u);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    reset();
    cin >> n >> m;
    for (long long i = 1; i <= m; i++) {
      int u, v;
      cin >> u >> v;
      if (u == v) continue;
      E[u].push_back(v);
    }
    for (long long i = 1; i <= n; i++) {
      if (!num[i]) visit(i);
    }
    for (long long u = 1; u <= n; u++) {
      for (auto v : E[u]) {
        if (tp[u] == tp[v]) continue;
        degout[tp[u]]++;
      }
    }
    if (cpm <= 1) {
      cout << "No" << endl;
      continue;
    }
    int vertex, val = INF;
    for (long long i = 1; i <= cpm; i++) {
      if (degout[i] < val) {
        val = degout[i];
        vertex = i;
      }
    }
    for (long long i = 1; i <= n; i++) {
      if (tp[i] == vertex) {
        r1.push_back(i);
      } else {
        r2.push_back(i);
      }
    }
    cout << "Yes" << endl;
    cout << (int)r1.size() << ' ' << (int)r2.size() << endl;
    for (long long i = 0; i <= (int)r1.size() - 1; i++) cout << r1[i] << ' ';
    cout << endl;
    for (long long i = 0; i <= (int)r2.size() - 1; i++) cout << r2[i] << ' ';
    cout << endl;
  }
}
