#include <bits/stdc++.h>
using namespace std;
stack<int> st;
vector<int> G[1000005];
int n, m, T, cnt, tot;
int dfn[1000005], low[1000005], scc[1000005], siz[1000005];
void dfs(int u) {
  st.push(u);
  dfn[u] = low[u] = ++cnt;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (!dfn[v]) {
      dfs(v);
      low[u] = min(low[u], low[v]);
    } else if (!scc[v])
      low[u] = min(low[u], dfn[v]);
  }
  if (dfn[u] == low[u]) {
    int v;
    tot++;
    do {
      v = st.top();
      st.pop();
      scc[v] = tot;
      siz[tot]++;
    } while (u != v);
  }
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d %d", &n, &m);
    cnt = 0, tot = 0;
    for (int i = 1; i <= n; i++)
      siz[i] = dfn[i] = low[i] = scc[i] = 0, G[i].clear();
    for (int i = 1, a, b; i <= m; i++) {
      scanf("%d %d", &a, &b);
      if (a != b) G[a].push_back(b);
    }
    for (int i = 1; i <= n; i++)
      if (!dfn[i]) dfs(i);
    if (tot == 1) {
      printf("No\n");
      continue;
    }
    printf("Yes\n%d %d\n", siz[1], n - siz[1]);
    for (int i = 1; i <= n; i++)
      if (scc[i] == 1) printf("%d ", i);
    printf("\n");
    for (int i = 1; i <= n; i++)
      if (scc[i] != 1) printf("%d ", i);
    printf("\n");
  }
  return 0;
}
