#include <bits/stdc++.h>
using namespace std;
const int MXN = 1000010;
const int C = 262144;
const int INF = 1000000001;
vector<int> G[MXN], GT[MXN];
int n, m;
int skla[MXN], scc;
int vis[MXN];
int s[MXN], ss;
int outdeg[MXN];
void dfs(int x) {
  vis[x] = 1;
  for (__typeof((G[x]).begin()) it = ((G[x]).begin()); it != (G[x]).end(); ++it)
    if (!vis[*it]) dfs(*it);
  s[ss++] = x;
}
void dfs2(int x) {
  vis[x] = 1;
  skla[x] = scc;
  for (__typeof((GT[x]).begin()) it = ((GT[x]).begin()); it != (GT[x]).end();
       ++it)
    if (!vis[*it]) dfs2(*it);
}
void test() {
  scanf("%d %d", &n, &m);
  for (int i = (1); i <= (m); i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    G[b].push_back(a);
    GT[a].push_back(b);
  }
  for (int i = (1); i <= (n); i++)
    if (!vis[i]) dfs(i);
  for (int i = (1); i <= (n); i++) vis[i] = 0;
  for (int i = (ss - 1); i >= (0); i--)
    if (!vis[s[i]]) {
      scc++;
      dfs2(s[i]);
    }
  for (int i = (1); i <= (n); i++)
    for (__typeof((G[i]).begin()) it = ((G[i]).begin()); it != (G[i]).end();
         ++it)
      if (skla[i] != skla[*it]) outdeg[skla[i]]++;
  int res = -1;
  for (int i = (1); i <= (scc); i++) {
    if (outdeg[i] == 0) res = i;
  }
  if (res != -1 && scc > 1) {
    int cnt = 0;
    vector<int> A, B;
    for (int i = (1); i <= (n); i++)
      if (skla[i] == res)
        B.push_back(i);
      else
        A.push_back(i);
    printf("Yes\n");
    printf("%d %d\n", (int)(A).size(), (int)(B).size());
    for (__typeof((A).begin()) it = ((A).begin()); it != (A).end(); ++it)
      printf("%d ", *it);
    printf("\n");
    for (__typeof((B).begin()) it = ((B).begin()); it != (B).end(); ++it)
      printf("%d ", *it);
    printf("\n");
  } else
    printf("No\n");
  for (int i = (1); i <= (n); i++) {
    G[i].clear();
    GT[i].clear();
    vis[i] = skla[i] = 0;
    outdeg[i] = 0;
  }
  ss = scc = 0;
}
int main() {
  int te = 1;
  scanf("%d", &te);
  while (te--) test();
  return 0;
}
