#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
vector<int> g[N], gr[N];
bool used[N];
vector<int> order, component;
pair<int, int> edge[N];
int par[N];
vector<int> v[N];
int f(int i) {
  if (par[i] != i) par[i] = f(par[i]);
  return par[i];
}
void merge(int a, int b) {
  a = f(a), b = f(b);
  if (a == b) return;
  par[a] = b;
}
void dfs1(int v) {
  used[v] = true;
  for (size_t i = 0; i < g[v].size(); ++i)
    if (!used[g[v][i]]) dfs1(g[v][i]);
  order.push_back(v);
}
void dfs2(int v) {
  used[v] = true;
  component.push_back(v);
  for (size_t i = 0; i < gr[v].size(); ++i)
    if (!used[gr[v][i]]) dfs2(gr[v][i]);
}
int main() {
  ios_base::sync_with_stdio(false);
  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(), gr[i].clear(), par[i] = i, v[i].clear();
    order.clear();
    component.clear();
    for (int i = 1; i <= n; i++) used[i] = false;
    for (int i = 0; i <= m - 1; i++) {
      int a, b;
      cin >> a >> b;
      edge[i] = make_pair(a, b);
      g[a].push_back(b);
      gr[b].push_back(a);
    }
    for (int i = 1; i <= n; ++i)
      if (!used[i]) dfs1(i);
    for (int i = 1; i <= n; i++) used[i] = false;
    for (int i = 0; i < n; ++i) {
      int v = order[n - 1 - i];
      if (!used[v]) {
        dfs2(v);
        int sz = component.size();
        for (int i = 0; i <= sz - 1; i++) merge(component[0], component[i]);
        component.clear();
      }
    }
    for (int i = 1; i <= n; i++) v[i].clear();
    set<int> s;
    for (int i = 1; i <= n; i++) {
      s.insert(f(i));
    }
    if (s.size() == 1) {
      cout << "No\n";
    } else {
      for (int i = 0; i <= m - 1; i++) {
        if (f(edge[i].first) == f(edge[i].second)) continue;
        v[f(edge[i].first)].push_back(f(edge[i].second));
      }
      set<int> s1;
      for (int i = 1; i <= n; i++) {
        if (v[f(i)].size() == 0) {
          for (int j = 1; j <= n; j++) {
            if (f(i) == f(j)) s1.insert(j);
          }
          break;
        }
      }
      cout << "Yes\n";
      cout << s1.size() << " " << n - s1.size();
      cout << "\n";
      for (__typeof(s1.begin()) it = s1.begin(); it != s1.end(); it++) {
        cout << *it;
        cout << " ";
      }
      cout << "\n";
      for (int i = 1; i <= n; i++) {
        if (!(s1.find(i) != s1.end())) {
          cout << i;
          cout << " ";
        }
      }
      cout << "\n";
    }
  }
  return 0;
}
