#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000010;
int T;
int N, M, k;
bool visited[MAX_N];
int ordered[MAX_N], scc[MAX_N];
vector<int> adj_out[MAX_N], adj_in[MAX_N];
void dfs1(int v) {
  visited[v] = true;
  for (auto u : adj_out[v])
    if (!visited[u]) dfs1(u);
  ordered[k++] = v;
}
void dfs2(int v) {
  visited[v] = true;
  scc[k++] = v;
  for (auto u : adj_in[v])
    if (!visited[u]) dfs2(u);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> T;
  for (int t = 1; t <= T; t++) {
    cin >> N >> M;
    for (int i = 1; i <= N; i++) {
      adj_out[i].clear();
      adj_in[i].clear();
    }
    for (int i = 0; i < M; i++) {
      int a, b;
      cin >> a >> b;
      adj_out[a].push_back(b);
      adj_in[b].push_back(a);
    }
    k = 0;
    fill(visited + 1, visited + N + 1, false);
    for (int i = 1; i <= N; i++)
      if (!visited[i]) dfs1(i);
    k = 0;
    fill(visited + 1, visited + N + 1, false);
    dfs2(ordered[N - 1]);
    if (k == N)
      cout << "No\n";
    else {
      cout << "Yes\n" << N - k << " " << k << "\n";
      for (int i = 1; i <= N; i++)
        if (!visited[i]) cout << i << " ";
      cout << "\n";
      for (int i = 0; i < k; i++) cout << scc[i] << " ";
      cout << "\n";
    }
  }
  return 0;
}
