#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 20;
const int MAXM = 1e6 + 20;
const int MOD = 1e9 + 7;
vector<int> vec[MAXN];
vector<int> jury, contestant;
int st[MAXN], dfn[MAXN], id[MAXN];
int n, m, scc, top, cnt;
int dfs(int u) {
  int lowu = dfn[u] = ++cnt;
  st[++top] = u;
  for (int i = 0; i < vec[u].size(); i++) {
    int v = vec[u][i];
    if (!dfn[v]) {
      int lowv = dfs(v);
      lowu = min(lowu, lowv);
    } else if (id[v] == 0)
      lowu = min(dfn[v], lowu);
  }
  if (dfn[u] == lowu) {
    scc++;
    do {
      if (scc == 1)
        jury.push_back(st[top]);
      else
        contestant.push_back(st[top]);
      id[st[top--]] = scc;
    } while (st[top + 1] != u);
  }
  return lowu;
}
void solve() {
  memset(dfn, 0, sizeof(int) * (n + 2));
  memset(id, 0, sizeof(int) * (n + 2));
  cnt = top = scc = 0;
  jury.clear(), contestant.clear();
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) dfs(i);
  if (scc == 1 || jury.size() == 0 || contestant.size() == 0) {
    puts("No");
  } else {
    puts("Yes");
    cout << jury.size() << " " << contestant.size() << endl;
    for (auto const& v : jury) cout << v << " ";
    puts("");
    for (auto const& v : contestant) cout << v << " ";
    puts("");
  }
}
int main() {
  int _;
  cin >> _;
  while (_--) {
    cin >> n >> m;
    while (m--) {
      int u, v;
      scanf("%d%d", &u, &v);
      if (u != v) vec[u].push_back(v);
    }
    solve();
    for (int i = 1; i <= n; i++) vec[i].clear();
  }
}
