#include <bits/stdc++.h>
using namespace std;
void read(long long &x) {
  char c = getchar();
  long long f = 1;
  x = 0;
  while (c < '0' || c > '9') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
}
void print(long long x) {
  if (x < 10) {
    putchar(x + '0');
    return;
  }
  print(x / 10);
  putchar(x % 10 + '0');
}
void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  print(x);
}
long long mint(long long a, long long b) { return a < b ? a : b; }
long long maxt(long long a, long long b) { return a < b ? b : a; }
stack<long long> s;
vector<long long> R[1000005];
bool instack[1000005];
long long t, n, m, low[1000005], dfn[1000005], cnt, col, siz;
bool vis[1000005];
void tarjan(long long u, long long fa) {
  s.push(u);
  dfn[u] = low[u] = ++cnt;
  instack[u] = 1;
  for (int i = 0; i < R[u].size(); i++) {
    long long v = R[u][i];
    if (!dfn[v]) {
      tarjan(v, u);
      low[u] = mint(low[u], low[v]);
    } else if (instack[v])
      low[u] = mint(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    col++;
    while (s.top() != u) {
      instack[s.top()] = 0;
      if (col == 1) vis[s.top()] = 1, siz++;
      s.pop();
    }
    if (col == 1) vis[u] = 1, siz++;
    instack[u] = 0;
    s.pop();
  }
}
int main() {
  read(t);
  while (t--) {
    read(n), read(m);
    for (int i = 1; i <= n; i++) dfn[i] = low[i] = vis[i] = 0, R[i].clear();
    col = cnt = siz = 0;
    for (int i = 1; i <= m; i++) {
      long long u, v;
      read(u), read(v);
      R[u].push_back(v);
    }
    for (int i = 1; i <= n; i++)
      if (!dfn[i]) tarjan(i, i);
    if (col == 1) {
      puts("No");
      continue;
    }
    puts("Yes");
    write(siz);
    putchar(' '), write(n - siz);
    putchar('\n');
    for (int i = 1; i <= n; i++)
      if (vis[i]) write(i), putchar(' ');
    putchar('\n');
    for (int i = 1; i <= n; i++)
      if (!vis[i]) write(i), putchar(' ');
    putchar('\n');
  }
}
