#include <bits/stdc++.h>
using namespace std;
vector<int> G[1000005], nG[1000005];
bool vis[1000005];
int tem[1000005], cur;
void dfs1(int u) {
  vis[u] = true;
  for (int v : G[u])
    if (!vis[v]) dfs1(v);
  tem[cur++] = u;
}
int ID[1000005];
vector<int> son[1000005];
void dfs2(int u, int scc) {
  ID[u] = scc;
  son[scc].emplace_back(u);
  for (int v : nG[u])
    if (ID[v] == -1) dfs2(v, scc);
}
bool leaf[1000005];
bool cho[1000005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) G[i].clear(), nG[i].clear();
    for (int i = 1, u, v; i <= m; i++) {
      cin >> u >> v;
      if (u != v) {
        G[u].emplace_back(v);
        nG[v].emplace_back(u);
      }
    }
    fill(vis + 1, vis + 1 + n, false);
    cur = 0;
    for (int u = 1; u <= n; u++)
      if (!vis[u]) dfs1(u);
    fill(ID + 1, ID + 1 + n, -1);
    int scc = 1;
    for (--cur; cur >= 0; cur--) {
      int u = tem[cur];
      if (ID[u] == -1) son[scc].clear(), dfs2(u, scc), scc++;
    }
    fill(leaf + 1, leaf + scc, true);
    for (int u = 1; u <= n; u++)
      for (int v : G[u])
        if (ID[u] != ID[v]) leaf[ID[u]] = false;
    vector<int> A, B;
    for (int i = 1; i < scc; i++)
      if (leaf[i] && (int)son[i].size() < n) {
        fill(cho + 1, cho + 1 + n, false);
        for (int u : son[i]) {
          A.emplace_back(u);
          cho[u] = true;
        }
        for (int v = 1; v <= n; v++)
          if (!cho[v]) B.emplace_back(v);
        break;
      }
    if (A.empty())
      cout << "No" << '\n';
    else {
      cout << "Yes" << '\n';
      cout << (int)A.size() << " " << (int)B.size() << '\n';
      for (int i = 0; i < (int)A.size(); i++) {
        if (i != 0) cout << " ";
        cout << A[i];
      }
      cout << '\n';
      for (int i = 0; i < (int)B.size(); i++) {
        if (i != 0) cout << " ";
        cout << B[i];
      }
      cout << '\n';
    }
  }
  return 0;
}
