#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const int MAXN = 1e6;
int n, m;
bool vis[MAXN + 1];
vector<int> v[MAXN + 1], temp;
;
stack<int> st;
void dfs(int node, int flag) {
  vis[node] = true;
  if (flag == 1) temp.push_back(node);
  for (int x : v[node]) {
    if (!vis[x]) dfs(x, flag);
  }
  st.push(node);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    scanf("%d", &m);
    for (int i = 1; i < n + 1; i++) {
      v[i].clear();
      vis[i] = false;
    }
    vector<int> ui, vi;
    for (int i = 0; i < m; i++) {
      int x, y;
      scanf("%d", &x);
      scanf("%d", &y);
      if (x != y) {
        v[x].push_back(y);
        ui.push_back(x);
        vi.push_back(y);
      }
    }
    while (!st.empty()) st.pop();
    for (int i = 1; i < n + 1; i++) {
      if (!vis[i]) dfs(i, 0);
    }
    for (int i = 1; i < n + 1; i++) {
      v[i].clear();
      vis[i] = false;
    }
    int sz = ui.size();
    for (int i = 0; i < sz; i++) {
      v[vi[i]].push_back(ui[i]);
    }
    int cmp = 0;
    while (!st.empty()) {
      int tp = st.top();
      st.pop();
      if (vis[tp]) continue;
      cmp++;
      temp.clear();
      dfs(tp, 1);
    }
    if (cmp == 1) {
      printf("No\n");
      continue;
    }
    map<int, int> mp;
    printf("Yes\n");
    printf("%d %d\n", temp.size(), n - temp.size());
    for (int x : temp) {
      printf("%d ", x);
      mp[x] = 1;
    }
    printf("\n");
    for (int i = 1; i <= n; i++) {
      if (mp.find(i) == mp.end()) printf("%d ", i);
    }
    printf("\n");
  }
  return 0;
}
