#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = false;
  while (!isdigit(c)) {
    if (c == '-') flag = true;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  if (flag) x = -x;
}
int T, n, m, dfn_cnt, col_cnt, top, cnt1, cnt2;
int dfn[1000010], low[1000010], st[1000010], col[1000010], d[1000010],
    p1[1000010], p2[1000010];
bool vis[1000010];
struct node {
  int x, y;
} ed[1000010];
struct edge {
  int to, nxt;
} e[1000010];
int head[1000010], edge_cnt;
void add(int from, int to) {
  e[++edge_cnt] = {to, head[from]}, head[from] = edge_cnt;
}
void tarjan(int x) {
  dfn[x] = low[x] = ++dfn_cnt, st[++top] = x, vis[x] = true;
  for (int i = head[x]; i; i = e[i].nxt) {
    int y = e[i].to;
    if (!dfn[y])
      tarjan(y), low[x] = min(low[x], low[y]);
    else if (vis[y])
      low[x] = min(low[x], dfn[y]);
  }
  if (low[x] == dfn[x]) {
    col_cnt++;
    int now;
    do now = st[top--], vis[now] = false, col[now] = col_cnt;
    while (now != x);
  }
}
void clear() {
  for (int i = 1; i <= n; ++i) head[i] = dfn[i] = low[i] = col[i] = d[i] = 0;
  edge_cnt = dfn_cnt = col_cnt = cnt1 = cnt2 = 0;
}
int main() {
  read(T);
  while (T--) {
    read(n), read(m);
    for (int i = 1; i <= m; ++i) {
      int x, y;
      read(x), read(y), add(x, y), ed[i] = {x, y};
    }
    for (int i = 1; i <= n; ++i)
      if (!dfn[i]) tarjan(i);
    if (col_cnt == 1) {
      puts("No"), clear();
      continue;
    }
    for (int i = 1; i <= m; ++i) {
      int x = ed[i].x, y = ed[i].y;
      if (col[x] == col[y]) continue;
      d[col[y]]++;
    }
    for (int i = 1; i <= col_cnt; ++i) {
      if (!d[i]) {
        for (int j = 1; j <= n; ++j) {
          if (col[j] != i)
            p1[++cnt1] = j;
          else
            p2[++cnt2] = j;
        }
        break;
      }
    }
    puts("Yes"), printf("%d %d\n", cnt1, cnt2);
    for (int i = 1; i <= cnt1; ++i) printf("%d%c", p1[i], " \n"[i == cnt1]);
    for (int i = 1; i <= cnt2; ++i) printf("%d%c", p2[i], " \n"[i == cnt2]);
    clear();
  }
  return 0;
}
