#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-8;
const long long INF = 0x3f3f3f3f3f3f3f3f;
inline long long readll() {
  long long x(0), op(1);
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') op = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * op;
}
const int sz_n = 1000015;
const int sz_m = 5000015;
stack<int> s;
struct edge {
  int f, t, nxt;
} l[sz_m];
int head[sz_n], tot = 0;
void build(int f, int t) {
  l[tot].f = f, l[tot].t = t, l[tot].nxt = head[f];
  head[f] = tot++;
}
int n, m;
int dfs_clock, low[sz_n], dfn[sz_n];
int scc[sz_n], scc_num;
int tarjan(int u) {
  low[u] = dfn[u] = ++dfs_clock;
  s.push(u);
  for (int i = head[u]; ~i; i = l[i].nxt) {
    int v = l[i].t;
    if (!dfn[v]) {
      low[v] = tarjan(v);
      low[u] = min(low[u], low[v]);
    } else if (!scc[v]) {
      low[u] = min(low[u], dfn[v]);
    }
  }
  if (dfn[u] == low[u]) {
    scc_num++;
    while (true) {
      int f = s.top();
      s.pop();
      scc[f] = scc_num;
      if (f == u) break;
    }
  }
  return low[u];
}
void init(int n) {
  for (int i = 0; i < n + 5; ++i) head[i] = -1, low[i] = dfn[i] = scc[i] = 0;
  while (!s.empty()) s.pop();
  tot = dfs_clock = scc_num = 0;
}
int c[sz_n];
int in1[sz_m], in2[sz_m];
int getd0() {
  int cnt = 0;
  for (int i = 1; i < scc_num + 1; ++i) {
    if (c[i] == 0) return i;
  }
  return -1;
}
vector<long long> jv, cv;
void solve() {
  int a, b;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &a, &b);
    in1[i] = a, in2[i] = b;
    if (a == b) continue;
    build(a, b);
  }
  for (int i = 1; i < n + 1; ++i) {
    if (!scc[i]) tarjan(i);
  }
  for (int i = 0; i < n + 5; ++i) head[i] = -1;
  tot = 0;
  for (int i = 0; i < m; ++i) {
    int a = in1[i], b = in2[i];
    a = scc[a], b = scc[b];
    if (a == b) continue;
    build(a, b);
  }
  for (int i = 0; i < n + 5; ++i) c[i] = 0;
  for (int u = 1; u < scc_num + 1; ++u) {
    for (int i = head[u]; ~i; i = l[i].nxt) {
      c[l[i].f]++;
    }
  }
  int jscc = getd0();
  jv.clear();
  cv.clear();
  for (int i = 1; i < n + 1; ++i) {
    if (scc[i] == jscc)
      jv.push_back(i);
    else
      cv.push_back(i);
  }
  if (((int)(jv.size())) > 0 && ((int)(jv.size())) < n) {
    puts("YES");
    printf("%d %d\n", ((int)(jv.size())), ((int)(cv.size())));
    for (int i = 0; i < ((int)(jv.size())); ++i) {
      if (i) putchar(' ');
      printf("%d", jv[i]);
    }
    puts("");
    for (int i = 0; i < ((int)(cv.size())); ++i) {
      if (i) putchar(' ');
      printf("%d", cv[i]);
    }
    puts("");
  } else {
    puts("NO");
  }
}
int main() {
  int _ = readll();
  while (_--) {
    scanf("%d%d", &n, &m);
    init(n);
    solve();
  }
  return 0;
}
