#include <bits/stdc++.h>
using namespace std;
inline long long QuickPow(long long x, long long y) {
  long long Res = 1, Temp = x;
  while (y) {
    if (y & 1) Res = Res * Temp % 1000000007;
    Temp = Temp * Temp % 1000000007;
    y /= 2;
  }
  return Res;
}
inline void Swap(long long &x, long long &y) {
  long long Temp = x;
  x = y;
  y = Temp;
}
inline long long Max(long long x, long long y) { return x > y ? x : y; }
inline long long Min(long long x, long long y) { return x < y ? x : y; }
inline void read(long long &x) {
  x = 0;
  long long f = 1;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + (s ^ 48);
    s = getchar();
  }
  x *= f;
}
vector<long long> G[1000005];
long long Dfn[1000005], Low[1000005], Cnt, Col, Size[1000005], Bel[1000005];
stack<long long> S;
bool InStack[1000005];
void Tarjan(long long x) {
  S.push(x);
  InStack[x] = 1;
  Dfn[x] = Low[x] = ++Cnt;
  int l = G[x].size();
  for (register long long i = 0; i < l; ++i) {
    long long to = G[x][i];
    if (!Dfn[to]) {
      Tarjan(to);
      Low[x] = Min(Low[x], Low[to]);
    } else if (InStack[to])
      Low[x] = Min(Low[x], Dfn[to]);
  }
  if (Dfn[x] == Low[x]) {
    Col++;
    long long u;
    do {
      Size[Col]++;
      u = S.top();
      Bel[u] = Col;
      S.pop();
      InStack[u] = 0;
    } while (u != x);
  }
}
int main() {
  long long T;
  read(T);
  while (T--) {
    long long n, m;
    read(n);
    read(m);
    Cnt = Col = 0;
    for (register long long i = 1; i <= n; ++i)
      G[i].clear(), Bel[i] = Size[i] = Dfn[i] = InStack[i] = 0;
    for (register long long i = 1; i <= m; ++i) {
      long long u, v;
      read(u);
      read(v);
      if (u == v) continue;
      G[u].push_back(v);
    }
    for (register long long i = 1; i <= n; ++i)
      if (!Dfn[i]) Tarjan(i);
    if (Col == 1) {
      printf("No\n");
      continue;
    }
    printf("Yes\n");
    printf("%lld %lld\n", Size[1], n - Size[1]);
    for (register long long i = 1; i <= n; ++i)
      if (Bel[i] == 1) printf("%d ", i);
    putchar('\n');
    for (register long long i = 1; i <= n; ++i)
      if (Bel[i] != 1) printf("%d ", i);
    putchar('\n');
  }
  return 0;
}
