#include <bits/stdc++.h>
using namespace std;
struct data {
  int to, head;
} e[1500000];
stack<int> s;
int head[1500000], len, n, t, m, cnt, num;
int la[1500000], sz[1500000], dfn[1500000], low[1500000], vis[1500000];
void add(int u, int v) {
  e[++len].to = v;
  e[len].head = head[u];
  head[u] = len;
}
void dfs(int lab) {
  dfn[lab] = low[lab] = ++cnt;
  s.push(lab);
  for (int i = head[lab]; i; i = e[i].head) {
    if (!dfn[e[i].to]) dfs(e[i].to);
    if (!vis[e[i].to]) low[lab] = min(low[lab], low[e[i].to]);
  }
  if (dfn[lab] == low[lab]) {
    la[lab] = ++num;
    sz[num] = vis[lab] = 1;
    int m1 = s.top();
    while (m1 != lab) {
      la[m1] = num;
      s.pop();
      vis[m1] = 1;
      m1 = s.top();
      sz[num]++;
    }
    s.pop();
  }
}
void print(int lab) {
  printf("Yes\n");
  printf("%d %d\n", sz[lab], n - sz[lab]);
  for (int i = 1; i <= n; i++)
    if (la[i] == lab) printf("%d ", i);
  printf("\n");
  for (int i = 1; i <= n; i++)
    if (la[i] != lab) printf("%d ", i);
}
int main() {
  int u, v;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
      head[i] = dfn[i] = low[i] = vis[i] = 0;
    }
    len = num = cnt = 0;
    for (int i = 1; i <= m; i++) {
      scanf("%d%d", &u, &v);
      if (u != v) add(u, v);
    }
    for (int i = 1; i <= n; i++) {
      if (!vis[i]) dfs(i);
    }
    if (num == 1)
      printf("No\n");
    else
      print(1);
  }
}
