#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
using namespace std;
const int N = 1e6 + 5;
vector<int> g[N], gg[N];
int T, n, m, a, b, cnt;
bool vis[N];
inline void dfs(int u) {
  vis[u] = true;
  ++cnt;
  for (int v : g[u]) {
    if (!vis[v]) {
      dfs(v);
    }
  }
}
inline void DFS(int u) {
  vis[u] = true;
  ++cnt;
  for (int v : gg[u]) {
    if (!vis[v]) {
      DFS(v);
    }
  }
}
inline void init() {
  for (int i = 1; i <= n; ++i) vis[i] = false;
  cnt = 0;
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= m; ++i) {
      scanf("%d %d", &a, &b);
      g[a].push_back(b);
      gg[b].push_back(a);
    }
    init();
    dfs(1);
    if (cnt == n) {
      init();
      DFS(1);
      if (cnt == n) {
        printf("No\n");
      } else {
        printf("Yes\n%d %d\n", n - cnt, cnt);
        for (int i = 1; i <= n; ++i)
          if (!vis[i]) printf("%d ", i);
        printf("\n");
        for (int i = 1; i <= n; ++i)
          if (vis[i]) printf("%d ", i);
        printf("\n");
      }
    } else {
      printf("Yes\n%d %d\n", cnt, n - cnt);
      for (int i = 1; i <= n; ++i)
        if (vis[i]) printf("%d ", i);
      printf("\n");
      for (int i = 1; i <= n; ++i)
        if (!vis[i]) printf("%d ", i);
      printf("\n");
    }
    for (int i = 1; i <= n; ++i) g[i].clear(), gg[i].clear();
  }
  return 0;
}
