#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
const int N = 2008000;
int n, m;
int head[N], to[N * 8], nxt[N * 8], edgenum;
inline void add(int u, int v) {
  to[++edgenum] = v;
  nxt[edgenum] = head[u];
  head[u] = edgenum;
}
int dfn[N], low[N], sta[N], top, col[N], num, cnt;
bool insta[N];
inline void tarjan(int u) {
  dfn[u] = low[u] = ++num;
  sta[++top] = u;
  insta[u] = 1;
  for (register int i = head[u]; i; i = nxt[i])
    if (!dfn[to[i]]) {
      tarjan(to[i]);
      low[u] = min(low[u], low[to[i]]);
    } else if (insta[to[i]])
      low[u] = min(low[u], dfn[to[i]]);
  if (dfn[u] == low[u]) {
    cnt++;
    while (1) {
      int x = sta[top--];
      insta[x] = 0;
      col[x] = cnt;
      if (x == u) break;
    }
  }
}
int main() {
  int T;
  read(T);
  while (T--) {
    read(n);
    read(m);
    for (register int i = (0); i <= (2 * n); i++)
      head[i] = dfn[i] = col[i] = insta[i] = 0;
    edgenum = 0;
    num = cnt = top = 0;
    for (register int i = (1); i <= (m); i++) {
      int u, v;
      read(u);
      read(v);
      if (u == v) continue;
      add(u, v);
    }
    for (register int i = (1); i <= (n); i++)
      if (!dfn[i]) tarjan(i);
    bool gg = 0;
    if (cnt == 1)
      puts("No");
    else {
      puts("Yes");
      vector<int> zuo, you;
      for (register int i = (1); i <= (n); i++)
        if (col[i] == 1)
          zuo.push_back(i);
        else
          you.push_back(i);
      printf("%d %d\n", ((int)zuo.size()), ((int)you.size()));
      for (register int i = (0); i <= (((int)zuo.size()) - 1); i++)
        printf("%d ", zuo[i]);
      puts("");
      for (register int i = (0); i <= (((int)you.size()) - 1); i++)
        printf("%d ", you[i]);
      puts("");
    }
  }
  return 0;
}
