#include <bits/stdc++.h>
using namespace std;
int tot;
const int M = 1e6 + 6;
vector<int> g1[M], g2[M];
int vis[M];
void dfs1(int u) {
  vis[u] = 1;
  tot++;
  for (int i = 0; i <= g1[u].size() - 1; ++i) {
    int v = g1[u][i];
    if (!vis[v]) dfs1(v);
  }
}
void dfs2(int u) {
  vis[u] = 1;
  tot++;
  for (int i = 0; i <= g2[u].size() - 1; ++i) {
    int v = g2[u][i];
    if (!vis[v]) dfs2(v);
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i <= n; i++) vis[i] = 0, g1[i].clear(), g2[i].clear();
    while (m--) {
      int u, v;
      scanf("%d%d", &u, &v);
      g1[u].push_back(v);
      g2[v].push_back(u);
    }
    tot = 0;
    int sign = 1;
    dfs1(1);
    if (tot == n) {
      tot = 0;
      sign = 0;
      for (int i = 0; i <= n; i++) vis[i] = 0;
      dfs2(1);
      if (tot == n) {
        puts("No");
        continue;
      }
      tot = n - tot;
    }
    puts("Yes");
    printf("%d %d\n", tot, n - tot);
    for (int i = 1; i <= n; ++i)
      if (vis[i] == sign) printf("%d ", i);
    puts("");
    for (int i = 1; i <= n; ++i)
      if (vis[i] != sign) printf("%d ", i);
    puts("");
  }
  return 0;
}
