#include <bits/stdc++.h>
using namespace std;
int N, s[1000100], c[1000100], sol[1000100];
vector<int> g[1000100], gt[1000100], v[1000100];
int viz[2 * 1000100], vz[2 * 1000100];
int x, y, M, T;
int X, Y, curr;
void dfs(int x) {
  viz[x] = 1;
  for (auto y : g[x])
    if (!viz[y]) dfs(y);
  s[++curr] = x;
}
void dfs2(int x, int comp) {
  viz[x] = 0;
  c[x] = comp;
  v[comp].push_back(x);
  for (auto y : gt[x])
    if (viz[y]) dfs2(y, comp);
}
bool f(int x, int val) {
  vz[x] = 1;
  for (auto y : v[x]) {
    if (sol[y] && sol[y] != val) return false;
    sol[y] = val;
  }
  return true;
}
inline void reset() {
  for (int i = 1; i <= N; ++i) {
    viz[i] = vz[i] = sol[i] = c[i] = s[i] = 0;
    g[i].clear();
    gt[i].clear();
    v[i].clear();
  }
  curr = X = Y = 0;
}
inline bool sat() {
  int comp = 0;
  for (int i = 1; i <= N; ++i)
    if (!viz[i]) dfs(i);
  for (int i = curr; i >= 1; --i)
    if (viz[s[i]]) dfs2(s[i], ++comp);
  f(comp, 2);
  for (int i = 1; i <= comp; ++i)
    if (!vz[i]) {
      if (!f(i, 1)) return false;
    }
  return true;
}
inline void add_edge(int x, int y) {
  g[x].push_back(y);
  gt[y].push_back(x);
}
int main() {
  cin.sync_with_stdio(false);
  cin >> T;
  while (T--) {
    cin >> N >> M;
    reset();
    for (int i = 1; i <= M; ++i) {
      cin >> x >> y;
      add_edge(x, y);
    }
    if (!sat()) {
      cout << "No\n";
      continue;
    }
    for (int i = 1; i <= N; ++i) {
      if (sol[i] == 2)
        ++X;
      else
        ++Y;
    }
    if (!X || !Y) {
      cout << "No\n";
    } else {
      cout << "Yes\n" << X << " " << Y << "\n";
      for (int i = 1; i <= N; ++i)
        if (sol[i] == 2) cout << i << " ";
      cout << "\n";
      for (int i = 1; i <= N; ++i)
        if (sol[i] == 1) cout << i << " ";
      cout << "\n";
    }
  }
}
