#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const int MAXN = 1e6;
int n, m;
bool vis[MAXN + 1], vis1[MAXN + 1];
vector<int> v[MAXN + 1], v1[MAXN + 1];
stack<int> st;
int cmp[MAXN + 1], cmp_no, cnt = 0;
void dfs(int node) {
  vis[node] = true;
  for (int x : v[node]) {
    if (!vis[x]) dfs(x);
  }
  st.push(node);
}
void dfs1(int node) {
  vis1[node] = true;
  cnt++;
  cmp[node] = cmp_no;
  for (int x : v1[node]) {
    if (!vis1[x]) dfs1(x);
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    scanf("%d", &m);
    for (int i = 1; i < n + 1; i++) {
      v[i].clear();
      v1[i].clear();
      vis[i] = false;
      vis1[i] = false;
    }
    for (int i = 0; i < m; i++) {
      int x, y;
      scanf("%d", &x);
      scanf("%d", &y);
      if (x != y) {
        v[x].push_back(y);
        v1[y].push_back(x);
      }
    }
    for (int i = 1; i < n + 1; i++) {
      if (!vis[i]) dfs(i);
    }
    cmp_no = 0;
    while (!st.empty()) {
      int tp = st.top();
      st.pop();
      if (vis1[tp]) continue;
      cnt = 0;
      cmp_no++;
      dfs1(tp);
    }
    if (cmp_no == 1) {
      printf("No\n");
      continue;
    }
    printf("Yes\n");
    printf("%d %d\n", cnt, n - cnt);
    for (int i = 1; i <= n; i++) {
      if (cmp[i] == cmp_no) {
        printf("%d ", i);
      }
    }
    printf("\n");
    for (int i = 1; i <= n; i++) {
      if (cmp[i] != cmp_no) {
        printf("%d ", i);
      }
    }
    printf("\n");
  }
  return 0;
}
