#include <bits/stdc++.h>
using namespace std;
const int maxN = 1 << 20;
int inCtr, sccCtr, low[maxN], in[maxN], scc[maxN], S[maxN], tp;
vector<int> G[maxN];
vector<int> jr, ct;
void clear(int n) {
  inCtr = sccCtr = tp = 0;
  for (int i = (0); i < (int)(n + 1); i++)
    low[i] = in[i] = scc[i] = S[i] = 0, G[i].resize(0);
  jr.resize(0);
  ct.resize(0);
}
int dfs(int v) {
  low[v] = in[v] = ++inCtr;
  S[tp++] = v;
  for (int u : G[v])
    if (in[u] >= 0) low[v] = min(low[v], in[u] == 0 ? dfs(u) : in[u]);
  if (in[v] != low[v]) return low[v];
  for (int u = -1; u != v;) {
    u = S[--tp];
    scc[u] = sccCtr;
    in[u] *= -1;
  }
  sccCtr++;
  return low[v];
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m;
    scanf("%d%d", &n, &m);
    while (m--) {
      int a, b;
      scanf("%d%d", &a, &b);
      G[a].push_back(b);
    }
    for (int i = (1); i < (int)(n + 1); i++)
      if (in[i] == 0) dfs(i);
    for (int i = (1); i < (int)(n + 1); i++)
      scc[i] == 0 ? jr.push_back(i) : ct.push_back(i);
    if (ct.empty())
      printf("No\n");
    else {
      printf("Yes\n%d %d\n", (int)jr.size(), (int)ct.size());
      for (int v : jr) printf("%d ", v);
      printf("\n");
      for (int v : ct) printf("%d ", v);
      printf("\n");
    }
    clear(n);
  }
  return 0;
}
