#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
int dir[8][2] = {-1, 0, 1, 0, 0, -1, 0, 1, -1, -1, -1, 1, 1, -1, 1, 1};
template <typename S, typename T>
inline bool Min(S &a, const T &b) {
  return a > b ? a = b, true : false;
}
template <typename S, typename T>
inline bool Max(S &a, const T &b) {
  return a < b ? a = b, true : false;
}
template <typename S, typename T>
inline void Adm(S &a, const T &b) {
  a = (a + b) % MOD;
  if (a < 0) a += MOD;
}
template <typename T>
inline bool IsPri(T x) {
  if (x < 2) return false;
  for (T i = 2; i * i <= x; ++i)
    if (x % i == 0) return false;
  return true;
}
template <typename T>
inline T _Gcd(T a, T b) {
  while (b) {
    T t = b;
    b = a % b;
    a = t;
  }
  return a;
}
template <typename T>
inline int _BitCnt(T x) {
  int cnt = 0;
  while (x) ++cnt, x &= x - 1;
  return cnt;
}
inline long long Pow(long long a, long long n) {
  long long t = 1;
  a %= MOD;
  while (n > 0) {
    if (n & 1) t = t * a % MOD;
    a = a * a % MOD, n >>= 1;
  }
  return t % MOD;
}
inline int read() {
  static char buf[1000000], *p1 = buf, *p2 = buf;
  register int x = false;
  register char ch =
      p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
          ? EOF
          : *p1++;
  ;
  register bool sgn = false;
  while (ch != '-' && (ch < '0' || ch > '9'))
    ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? EOF
             : *p1++;
  ;
  if (ch == '-')
    sgn = true,
    ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? EOF
             : *p1++;
  ;
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48),
    ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? EOF
             : *p1++;
  ;
  return sgn ? -x : x;
}
const int N = 1e6 + 100;
vector<int> e[N];
int dfn[N], low[N], bel[N], idx, num;
int stk[N], top;
bool ins[N];
void Tarjan(int x) {
  dfn[x] = low[x] = ++idx;
  stk[++top] = x, ins[x] = 1;
  for (int y : e[x])
    if (!dfn[y])
      Tarjan(y), Min(low[x], low[y]);
    else if (ins[y])
      Min(low[x], dfn[y]);
  if (low[x] == dfn[x]) {
    int y;
    ++num;
    do {
      y = stk[top--], ins[y] = 0;
      bel[y] = num;
    } while (y != x);
  }
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i <= n + 5; ++i) e[i].clear();
    memset((dfn), (0), sizeof((dfn)[0]) * (n + 5)), idx = num = 0;
    for (int i = 1; i <= m; ++i) {
      int u, v;
      scanf("%d%d", &u, &v);
      e[u].push_back(v);
    }
    for (int i = 1; i <= n; ++i)
      if (!dfn[i]) Tarjan(i);
    if (num == 1)
      puts("No");
    else {
      puts("Yes");
      vector<int> a, b;
      for (int i = 1; i <= n; ++i)
        if (bel[i] == 1)
          a.push_back(i);
        else
          b.push_back(i);
      cout << ((int)(a).size()) << ' ' << ((int)(b).size()) << endl;
      for (int x : a) printf("%d ", x);
      puts("");
      for (int x : b) printf("%d ", x);
      puts("");
    }
  }
  return 0;
}
