#include <bits/stdc++.h>
using namespace std;
class DebugStream {
} LOG;
template <typename T>
DebugStream &operator<<(DebugStream &s, const T &) {
  return s;
}
mt19937 rnd(time(NULL));
const int maxN = 1e6 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20,
          bs = 29;
vector<int> adj[maxN], jda[maxN];
int n, m, compo[maxN], cc;
stack<int> stc;
bool vi[maxN];
void dfs1(int nd) {
  if (vi[nd]) return;
  vi[nd] = 1;
  for (int sn : adj[nd]) dfs1(sn);
  stc.push(nd);
}
void dfs2(int nd) {
  if (compo[nd] != -1) return;
  compo[nd] = cc;
  for (int sn : jda[nd]) dfs2(sn);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      compo[i] = -1;
      adj[i].clear();
      jda[i].clear();
      vi[i] = 0;
    }
    for (int u, v, i = 0; i < m; i++) {
      cin >> u >> v;
      u--, v--;
      if (u == v) continue;
      adj[u].push_back(v);
      jda[v].push_back(u);
    }
    for (int i = 0; i < n; i++) dfs1(i);
    cc = 0;
    while (stc.size()) {
      dfs2(stc.top()), cc++;
      while (stc.size() && compo[stc.top()] != -1) stc.pop();
    }
    if (cc == 1)
      cout << "No\n";
    else {
      cout << "Yes\n";
      vector<int> one, two;
      for (int i = 0; i < n; i++)
        if (compo[i] == cc - 1)
          one.push_back(i);
        else
          two.push_back(i);
      cout << one.size() << ' ' << two.size() << '\n';
      for (auto el : one) cout << el + 1 << ' ';
      cout << '\n';
      for (auto el : two) cout << el + 1 << ' ';
      cout << '\n';
    }
  }
}
