#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
int n, m, dfn[N], low[N], tim, st[N], bel[N], tt, tp, u[N], v[N];
vector<int> E[N];
bool in[N];
void dfs(int u) {
  dfn[u] = low[u] = ++tim;
  st[++tp] = u;
  in[u] = 1;
  for (auto v : E[u]) {
    if (!dfn[v])
      dfs(v), low[u] = min(low[u], low[v]);
    else if (in[v])
      low[u] = min(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    int v;
    ++tt;
    do v = st[tp--], bel[v] = tt, in[v] = 0;
    while (u != v);
  }
}
int main() {
  int T = gi();
  while (T--) {
    n = gi(), m = gi();
    for (int i = 1; i <= m; i++)
      u[i] = gi(), v[i] = gi(), E[u[i]].push_back(v[i]);
    for (int i = 1; i <= n; i++)
      if (!dfn[i]) dfs(i);
    int x = 0, y = 0;
    for (int i = 1; i <= n && !x; i++)
      for (auto j : E[i])
        if (bel[i] != bel[j]) {
          x = i, y = j;
          break;
        }
    if (!x) {
      x = 1;
      for (int i = 2; i <= n; i++)
        if (bel[i] != bel[1]) {
          y = i;
          break;
        }
    }
    for (int i = 1; i <= n; i++) E[i].clear(), dfn[i] = 0;
    int pre = tt;
    tim = tt = 0;
    if (pre == 1) {
      cout << "No\n";
      continue;
    }
    for (int i = 1; i <= m; i++) {
      E[u[i]].push_back(v[i]);
      E[v[i] + n].push_back(u[i] + n);
    }
    E[x].push_back(x + n);
    E[y + n].push_back(y);
    for (int i = 1; i <= n + n; i++)
      if (!dfn[i]) dfs(i);
    cout << "Yes\n";
    vector<int> A, B;
    for (int i = 1; i <= n; i++) {
      if (bel[i] < bel[i + n])
        A.push_back(i);
      else
        B.push_back(i);
    }
    cout << int(A.size()) << ' ' << int(B.size()) << '\n';
    for (auto x : A) cout << x << ' ';
    cout << '\n';
    for (auto x : B) cout << x << ' ';
    cout << '\n';
    for (int i = 1; i <= n + n; i++) E[i].clear(), dfn[i] = 0;
    tim = tt = 0;
  }
  return 0;
}
