#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 10;
const int N = maxN;
vector<int> G[maxN];
const int inf = 1000000000;
int num, top, now, cnt, ans;
int dfn[N], low[N], Stack[N], ins[N], belong[N], to[N], money[N];
int mini[N];
void tarjan(int v) {
  dfn[v] = low[v] = ++now;
  Stack[++top] = v;
  ins[v] = 1;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i];
    if (!dfn[u]) {
      tarjan(u);
      low[v] = min(low[v], low[u]);
    } else if (ins[u]) {
      low[v] = min(low[v], dfn[u]);
    }
  }
  if (low[v] == dfn[v]) {
    int tmp;
    cnt++;
    do {
      tmp = Stack[top--];
      belong[tmp] = cnt;
      if (money[tmp] < mini[cnt]) {
        mini[cnt] = money[tmp];
      }
      ins[tmp] = 0;
    } while (tmp != v);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cnt = now = ans = num = top = 0;
    int n, m;
    cin >> n >> m;
    int a, b;
    for (int i = 0; i <= n; i++) {
      dfn[i] = low[i] = ins[i] = to[i] = 0;
      mini[i] = inf;
    }
    for (int i = 0; i < m; i++) {
      cin >> a >> b;
      if (a != b) {
        G[a].push_back(b);
      }
    }
    for (int i = 1; i <= n; i++) {
      if (!dfn[i]) tarjan(i);
    }
    if (cnt == 1) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
      int ret = 0;
      for (int i = 1; i <= n; i++) {
        ret += (belong[i] == 1);
      }
      cout << ret << " " << n - ret << endl;
      for (int i = 1; i <= n; i++) {
        if (belong[i] == 1) cout << i << " ";
      }
      cout << endl;
      for (int i = 1; i <= n; i++) {
        if (belong[i] != 1) cout << i << " ";
      }
      cout << endl;
    }
    for (int i = 1; i <= n; i++) G[i].clear();
  }
  return 0;
}
