#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 20;
long long dp[2][maxn], ps[maxn], dis1[maxn];
double d[maxn];
long long mod = 1e9 + 7;
bool vis[maxn], visit1[maxn];
const long long inf = 1e18;
vector<int> vec[maxn];
vector<int> vec1[maxn];
queue<int> q;
int l, r;
int ans = 0;
int n, m;
void dfs(int u) {
  vis[u] = 1;
  ans++;
  for (int i = 0; i < vec[u].size(); i++)
    if (!vis[vec[u][i]]) dfs(vec[u][i]);
}
void dfs1(int u) {
  vis[u] = 1;
  ans++;
  for (int i = 0; i < vec1[u].size(); i++)
    if (!vis[vec1[u][i]]) dfs1(vec1[u][i]);
}
void clear() {
  for (int i = 1; i <= n; i++) {
    vis[i] = 0;
    vec[i].clear();
    vec1[i].clear();
  }
  ans = 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    cin >> n >> m;
    clear();
    int u, v;
    for (int i = 0; i < m; i++) {
      cin >> u >> v;
      vec[u].push_back(v);
      vec1[v].push_back(u);
    }
    ans = 0;
    dfs(1);
    if (n > ans) {
      cout << "YES" << endl << ans << ' ' << n - ans << endl;
      for (int i = 1; i <= n; i++)
        if (vis[i]) cout << i << ' ';
      cout << endl;
      for (int i = 1; i <= n; i++)
        if (!vis[i]) cout << i << ' ';
      cout << endl;
      goto y;
    }
    ans = 0;
    for (int i = 1; i <= n; i++) vis[i] = 0;
    dfs1(1);
    if (n > ans) {
      cout << "YES" << endl << n - ans << " " << ans << endl;
      for (int i = 1; i <= n; i++)
        if (!vis[i]) cout << i << " ";
      cout << endl;
      for (int i = 1; i <= n; i++)
        if (vis[i]) cout << i << " ";
      cout << endl;
      goto y;
    }
    cout << "NO" << endl;
  y : {}
  }
}
