#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
const int M = 1000005;
vector<int> adj[M], adjj[M];
int vis[M];
stack<int> st;
void toposort(int x) {
  vis[x] = 1;
  for (auto y : adj[x]) {
    if (vis[y]) continue;
    toposort(y);
  }
  st.push(x);
}
int cm1[M], cm2[M], c1, c2;
void scc(int x) {
  vis[x] = 1;
  cm1[c1++] = x;
  for (auto y : adjj[x]) {
    if (vis[y]) continue;
    scc(y);
  }
}
int main() {
  int t, tt = 1;
  scanf("%d", &t);
  while (t--) {
    int n, m, x, y;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < (m); i++) {
      scanf("%d %d", &x, &y);
      if (x == y) continue;
      adj[x].emplace_back(y);
      adjj[y].emplace_back(x);
    }
    for (int i = 1; i <= n; i++) vis[i] = 0;
    for (int i = 1; i <= n; i++) {
      if (vis[i]) continue;
      toposort(i);
    }
    for (int i = 1; i <= n; i++) vis[i] = 0;
    c1 = c2 = 0;
    while (st.size()) {
      x = st.top();
      st.pop();
      if (vis[x]) continue;
      scc(x);
      break;
    }
    while (st.size()) st.pop();
    for (int i = 1; i <= n; i++) {
      adj[i].clear();
      adjj[i].clear();
    }
    if (c1 == n) {
      printf("No\n");
      continue;
    }
    for (int i = 1; i <= n; i++) {
      if (!vis[i]) cm2[c2++] = i;
    }
    printf("Yes\n");
    printf("%d %d\n", c2, c1);
    for (int i = 0; i < (c2); i++) printf("%d ", cm2[i]);
    printf("\n");
    for (int i = 0; i < (c1); i++) printf("%d ", cm1[i]);
    printf("\n");
  }
  return 0;
}
