#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e6 + 5;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
long long t, n, m, col[maxn], mex = 1;
vector<long long> in[maxn], out[maxn], tpl;
bool mrk[maxn];
void sfd(long long u) {
  mrk[u] = 1;
  for (long long j : out[u]) {
    if (mrk[j]) continue;
    sfd(j);
  }
  tpl.push_back(u);
}
void dfs(long long u) {
  col[u] = mex;
  for (long long j : in[u]) {
    if (col[j]) continue;
    dfs(j);
  }
}
void pak() {
  mex = 1;
  tpl.clear();
  for (long long i = 1; i <= n + n; i++) {
    col[i] = 0;
    mrk[i] = 0;
    in[i].clear();
    out[i].clear();
  }
}
void solve() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    if (u == v) {
      out[v + n].push_back(u);
      in[u].push_back(v + n);
    } else {
      out[u].push_back(v + n);
      in[v + n].push_back(u);
    }
  }
  for (long long i = 1; i <= n + n; i++) {
    if (mrk[i]) continue;
    sfd(i);
  }
  reverse(tpl.begin(), tpl.end());
  for (long long i : tpl) {
    if (col[i]) continue;
    dfs(i);
    mex++;
  }
  if ((mex == 2) || (n == 1)) {
    pak();
    cout << "No"
         << "\n";
    return;
  }
  vector<long long> v1, v2;
  for (long long i = n + 1; i <= n + n; i++) {
    if (col[i] == 1)
      v1.push_back(i - n);
    else
      v2.push_back(i - n);
  }
  cout << "Yes"
       << "\n";
  cout << v2.size() << ' ' << v1.size() << "\n";
  for (long long i : v2) cout << i << ' ';
  cout << "\n";
  for (long long i : v1) cout << i << ' ';
  cout << "\n";
  pak();
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> t;
  while (t--) {
    solve();
  }
}
