#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long llinf = (1LL << 62);
const int inf = (1 << 30);
const int nmax = 1e6 + 50;
const int mod = 1e9 + 7;
using namespace std;
int n, x, y, t, j, i, c[nmax], cl[nmax], k, viz[nmax], m;
vector<int> a[nmax], r[nmax], ord;
void dfs(int x) {
  viz[x] = 1;
  for (int i = 0; i < a[x].size(); i++) {
    if (viz[a[x][i]]) continue;
    dfs(a[x][i]);
  }
  ord.push_back(x);
}
void col(int x) {
  c[x] = k;
  for (int i = 0; i < r[x].size(); i++) {
    if (c[r[x][i]]) continue;
    col(r[x][i]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (i = 1; i <= n; i++) {
      a[i].clear();
      r[i].clear();
      viz[i] = 0;
      c[i] = 0;
      cl[i] = 0;
    }
    ord.clear();
    k = 0;
    while (m--) {
      cin >> x >> y;
      a[x].push_back(y);
      r[y].push_back(x);
    }
    for (i = 1; i <= n; i++) {
      if (viz[i]) continue;
      dfs(i);
    }
    reverse(ord.begin(), ord.end());
    for (i = 0; i < n; i++) {
      if (c[ord[i]]) continue;
      k++;
      col(ord[i]);
    }
    if (k == 1)
      cout << "NO\n";
    else {
      for (i = 1; i <= n; i++) {
        for (j = 0; j < a[i].size(); j++) {
          if (c[i] != c[a[i][j]]) cl[c[a[i][j]]] = 1;
        }
      }
      for (i = 1; i <= k; i++) {
        if (!cl[i]) {
          j = i;
          break;
        }
      }
      x = y = 0;
      for (i = 1; i <= n; i++) {
        if (c[i] != j)
          x++;
        else
          y++;
      }
      cout << "YES\n" << x << ' ' << y << '\n';
      for (i = 1; i <= n; i++)
        if (c[i] != j) cout << i << ' ';
      cout << '\n';
      for (i = 1; i <= n; i++)
        if (c[i] == j) cout << i << ' ';
      cout << '\n';
    }
  }
  return 0;
}
