#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
struct node {
  int to, next;
} e[N];
int cnt, head[N];
void add(int x, int y) {
  e[cnt].to = y;
  e[cnt].next = head[x];
  head[x] = cnt++;
}
int low[N], dfn[N], scc[N], tim, num;
stack<int> st;
bool in[N];
void init(int siz) {
  memset(head, -1, sizeof(int) * (siz + 1));
  cnt = tim = num = 0;
  memset(dfn, 0, sizeof(int) * (siz + 1));
  memset(in, 0, sizeof(bool) * (siz + 1));
  while (!st.empty()) st.pop();
}
void tarjan(int x) {
  low[x] = dfn[x] = ++tim;
  st.push(x);
  in[x] = 1;
  for (int i = head[x]; ~i; i = e[i].next) {
    int ne = e[i].to;
    if (!dfn[ne])
      tarjan(ne), low[x] = min(low[x], low[ne]);
    else if (in[ne])
      low[x] = min(low[x], dfn[ne]);
  }
  if (low[x] == dfn[x]) {
    ++num;
    while (1) {
      int v = st.top();
      st.pop();
      scc[v] = num;
      in[v] = 0;
      if (x == v) break;
    }
  }
}
vector<int> a1, a2;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m;
    scanf("%d%d", &n, &m);
    init(n * 2);
    int x, y;
    for (int i = 1; i <= m; i++) scanf("%d%d", &x, &y), add(x, n + y);
    for (int i = 1; i <= n; i++) add(n + i, i);
    for (int i = 1; i <= n; i++)
      if (!dfn[i]) tarjan(i);
    if (num == 1) {
      printf("No\n");
      continue;
    }
    a1.clear(), a2.clear();
    for (int i = 1; i <= n; i++)
      if (scc[i] == 1)
        a1.push_back(i);
      else
        a2.push_back(i);
    printf("Yes\n");
    printf("%d %d\n", a1.size(), a2.size());
    for (auto i : a1) printf("%d ", i);
    printf("\n");
    for (auto i : a2) printf("%d ", i);
    printf("\n");
  }
  return 0;
}
