#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int h1[N], h2[N], e[N << 1], ne[N << 1], idx;
int n, m;
vector<int> v1, v2;
bool st[N];
void add(int h[], int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
void dfs(int u, vector<int> &v, int h[]) {
  st[u] = true;
  v.push_back(u);
  for (int i = h[u]; ~i; i = ne[i]) {
    int p = e[i];
    if (st[p]) continue;
    dfs(p, v, h);
  }
}
void solve() {
  scanf("%d%d", &n, &m);
  idx = 0;
  v1.clear();
  v2.clear();
  for (int i = 1; i <= n; i++) {
    h1[i] = h2[i] = -1;
    st[i] = false;
  }
  while (m--) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (a != b) {
      add(h1, a, b);
      add(h2, b, a);
    }
  }
  dfs(1, v1, h1);
  if (v1.size() != n) {
    puts("YES");
    for (int i = 1; i <= n; i++)
      if (!st[i]) v2.push_back(i);
    printf("%u %u\n", v1.size(), v2.size());
    for (auto x : v1) printf("%d ", x);
    puts("");
    for (auto x : v2) printf("%d ", x);
    puts("");
    return;
  }
  v1.clear();
  for (int i = 1; i <= n; i++) st[i] = false;
  dfs(1, v2, h2);
  if (v2.size() != n) {
    puts("YES");
    for (int i = 1; i <= n; i++)
      if (!st[i]) v1.push_back(i);
    printf("%u %u\n", v1.size(), v2.size());
    for (auto x : v1) printf("%d ", x);
    puts("");
    for (auto x : v2) printf("%d ", x);
    puts("");
    return;
  }
  puts("NO");
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    solve();
  }
  return 0;
}
