#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100;
vector<int> g[maxn];
int n, m;
int dfn[maxn];
int scc[maxn];
int low[maxn];
int sta[maxn];
bool vis[maxn];
int stp = 0;
int ind = 0;
int num = 0;
void tarjan(int u) {
  dfn[u] = low[u] = ++stp;
  vis[u] = 1;
  sta[++ind] = u;
  for (auto i : g[u]) {
    if (dfn[i] == 0) {
      tarjan(i);
      low[u] = min(low[u], low[i]);
    } else if (vis[i]) {
      low[u] = min(low[u], low[i]);
    }
  }
  if (dfn[u] == low[u]) {
    ++num;
    do {
      scc[sta[ind]] = num;
      vis[sta[ind]] = 0;
      --ind;
    } while (sta[ind + 1] != u);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
      g[i].clear();
      dfn[i] = low[i] = 0;
      vis[i] = 0;
      scc[i] = 0;
    }
    stp = num = ind = 0;
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      if (a != b) g[a].push_back(b);
    }
    for (int i = 1; i <= n; ++i) {
      if (!dfn[i]) {
        tarjan(i);
      }
    }
    if (num == 1) {
      cout << "No" << endl;
    } else {
      int ans = 0;
      for (int i = 1; i <= n; ++i) {
        if (scc[i] == 1) {
          ++ans;
          vis[i] = 1;
        }
      }
      cout << "Yes" << endl;
      cout << ans << " " << n - ans << endl;
      for (int i = 1; i <= n; ++i) {
        if (vis[i]) {
          cout << i << " ";
        }
      }
      cout << endl;
      for (int i = 1; i <= n; ++i) {
        if (!vis[i]) {
          cout << i << " ";
        }
      }
      cout << endl;
    }
  }
  return 0;
}
