#include <bits/stdc++.h>
using namespace std;
bool vst[1000000 + 10];
vector<int> vec[1000000 + 10], bac[1000000 + 10], com[1000000 + 1], tp;
int cn;
void dfs(int cur) {
  if (vst[cur]) return;
  vst[cur] = true;
  for (auto nxt : vec[cur]) dfs(nxt);
  tp.push_back(cur);
  return;
}
void dfs2(int cur) {
  if (vst[cur]) return;
  vst[cur] = true;
  com[cn].push_back(cur);
  for (auto nxt : bac[cur]) dfs2(nxt);
  return;
}
int mp[1000000 + 10], total;
void prnt(int n) {
  int x = n - total;
  printf("Yes\n%d %d\n", total, x);
  bool ch = false;
  for (long long i = 1; i <= n; i++)
    if (mp[i]) {
      if (ch) printf(" ");
      printf("%d", i);
      ch = true;
    }
  printf("\n");
  ch = false;
  for (long long i = 1; i <= n; i++)
    if (mp[i] == false) {
      if (ch) printf(" ");
      printf("%d", i);
      ch = true;
    }
  printf("\n");
  ch = false;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m, u, v;
    scanf("%d %d", &n, &m);
    for (long long i = 0; i <= n; i++)
      vec[i].clear(), bac[i].clear(), com[i].clear(), vst[i] = false,
                                                      mp[i] = false;
    total = 0;
    tp.clear(), cn = 0;
    while (m--) {
      scanf("%d %d", &u, &v);
      vec[u].push_back(v);
      bac[v].push_back(u);
    }
    for (long long i = 1; i <= n; i++)
      if (vst[i] == false) dfs(i);
    for (long long i = 1; i <= n; i++) vst[i] = false;
    while (!tp.empty()) {
      int cur = tp.back();
      tp.pop_back();
      if (vst[cur] == false) {
        dfs2(cur);
        cn++;
      }
    }
    for (auto nxt : com[cn - 1]) mp[nxt] = true, total++;
    if (total == n)
      printf("No\n");
    else
      prnt(n);
  }
  return 0;
}
