#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
vector<int> g[N];
int lw[N], idx[N], qidx, cmp[N], qcmp;
stack<int> st;
void tjn(int u) {
  lw[u] = idx[u] = ++qidx;
  st.push(u);
  cmp[u] = -2;
  for (int v : g[u]) {
    if (!idx[v] || cmp[v] == -2) {
      if (!idx[v]) tjn(v);
      lw[u] = min(lw[u], lw[v]);
    }
  }
  if (lw[u] == idx[u]) {
    int x, l = -1;
    do {
      x = st.top();
      st.pop();
      cmp[x] = qcmp;
    } while (x != u);
    qcmp++;
  }
}
void scc(int n) {
  for (int i = 0; i < n; i++) idx[i] = 0, cmp[i] = -1;
  qidx = 0;
  qcmp = 0;
  for (int i = 0; i < n; i++)
    if (!idx[i]) tjn(i);
}
vector<pair<int, int>> edges;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      edges.push_back({a, b});
    }
    for (auto e : edges) {
      if (e.first == e.second) {
        g[e.first].push_back(e.second + n);
      } else {
        g[e.second + n].push_back(e.first);
      }
    }
    scc(2 * n);
    if (qcmp == 1 || n == 1) {
      cout << "No" << '\n';
    } else {
      int in[qcmp];
      memset(in, 0, sizeof(in));
      for (auto e : edges)
        if (cmp[e.first] != cmp[e.second + n]) {
          if (e.first == e.second) {
            in[cmp[e.second + n]]++;
          } else {
            in[cmp[e.first]]++;
          }
        }
      int ch = 0;
      while (ch < qcmp && in[ch] != 0) ch++;
      assert(ch < qcmp);
      bool jury[n], cats[n];
      memset(jury, false, sizeof(jury));
      memset(cats, true, sizeof(cats));
      int nj = 0, nc = n;
      for (int i = 0; i < n; i++)
        if (cmp[i] == ch) jury[i] = 1, cats[i] = 0, nj++, nc--;
      cout << "Yes" << '\n';
      cout << nj << " " << nc << '\n';
      for (int i = 0; i < n; i++)
        if (jury[i]) cout << i + 1 << " ";
      cout << '\n';
      for (int i = 0; i < n; i++)
        if (cats[i]) cout << i + 1 << " ";
      cout << '\n';
    }
    for (int i = 0; i < 2 * n; i++) g[i].clear();
    edges.clear();
  }
  return 0;
}
