#include <bits/stdc++.h>
using namespace std;
void addEdge(vector<long long> adj[], vector<long long> adjT[], long long u,
             long long v) {
  adj[u].push_back(v);
  adjT[v].push_back(u);
}
void dfs(long long u, vector<long long> adj[], long long visited[],
         stack<long long> &s, long long flag) {
  long long i, v;
  for (i = 0; i < adj[u].size(); i++) {
    v = adj[u][i];
    if (!visited[v]) {
      visited[v] = 1;
      dfs(v, adj, visited, s, flag);
    }
  }
  if (flag == 1) s.push(u);
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  string str;
  while (t--) {
    long long n, m, u, v, i;
    cin >> n >> m;
    vector<long long> adj[n + 1];
    vector<long long> adjT[n + 1];
    stack<long long> s;
    vector<long long> jury, part;
    long long visited[n + 1];
    memset(visited, 0, sizeof(visited));
    while (m--) {
      cin >> u >> v;
      addEdge(adj, adjT, u, v);
    }
    for (i = 1; i <= n; i++) {
      if (!visited[i]) {
        visited[i] = 1;
        dfs(i, adj, visited, s, 1);
      }
    }
    memset(visited, 0, sizeof(visited));
    u = s.top();
    if (!visited[u]) {
      visited[u] = 1;
      dfs(u, adjT, visited, s, 0);
    }
    for (i = 1; i <= n; i++) {
      if (visited[i])
        part.push_back(i);
      else
        jury.push_back(i);
    }
    if (jury.size() == n || part.size() == n)
      cout << "No" << endl;
    else {
      cout << "Yes" << endl;
      cout << jury.size() << " " << part.size() << endl;
      for (i = 0; i < jury.size() - 1; i++) cout << jury[i] << " ";
      cout << jury[i] << endl;
      for (i = 0; i < part.size() - 1; i++) cout << part[i] << " ";
      cout << part[i] << endl;
    }
    getline(cin, str);
  }
  return 0;
}
