#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e6 + 100;
const int mod = (int)1e9 + 7;
int n, m, used[maxn], q;
vector<int> g[maxn], gr[maxn];
vector<int> cur, order;
void print(vector<int> a, vector<int> b) {
  puts("YES");
  printf("%d %d\n", ((int)(a).size()), ((int)(b).size()));
  for (auto v : a) printf("%d ", v);
  printf("\n");
  for (auto v : b) printf("%d ", v);
  printf("\n");
}
void dfs(int v) {
  used[v] = 1;
  for (auto to : g[v])
    if (!used[to]) dfs(to);
  order.push_back(v);
}
int col[maxn], timer, sz;
void dfs1(int v) {
  used[v] = 0;
  col[v] = timer;
  sz++;
  cur.push_back(v);
  for (auto to : gr[v])
    if (used[to]) dfs1(to);
}
void solve() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (n); ++i)
    g[i].clear(), gr[i].clear(), col[i] = used[i] = 0;
  order.clear();
  for (int i = (1); i <= (m); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    gr[v].push_back(u);
  }
  for (int i = (1); i <= (n); ++i)
    if (!used[i]) dfs(i);
  reverse((order).begin(), (order).end());
  for (auto v : order) {
    if (used[v]) {
      sz = 0, timer++;
      cur.clear();
      dfs1(v);
      if (sz < n) {
        int bad = 0;
        for (auto x : cur)
          for (auto to : g[x])
            if (col[to] != timer) bad = 1;
        if (bad) continue;
        vector<int> a, b;
        for (int i = (1); i <= (n); ++i) {
          if (col[i] == timer)
            a.push_back(i);
          else
            b.push_back(i);
        }
        print(a, b);
        return;
      }
    }
  }
  puts("NO");
}
int main() {
  scanf("%d", &q);
  while (q--) solve();
}
