#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int T, N, M, dfn[maxn], low[maxn], s[maxn], Index = 0, scc = 0, cnt = 0,
                                            belong[maxn];
bool vis[maxn];
vector<int> edges[maxn];
vector<int> Scc[maxn];
void tarjan(int u) {
  low[u] = dfn[u] = ++cnt;
  s[++Index] = u;
  vis[u] = true;
  for (int i = 0; i < edges[u].size(); i++) {
    int v = edges[u][i];
    if (!dfn[v]) {
      tarjan(v);
      low[u] = min(low[v], low[u]);
    } else if (vis[v])
      low[u] = min(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    scc++;
    Scc[scc].clear();
    int cur;
    for (;;) {
      cur = s[Index--];
      belong[cur] = scc;
      Scc[scc].push_back(cur);
      vis[cur] = false;
      if (cur == u) break;
    }
  }
}
void init() {
  for (int i = 1; i <= N; i++) edges[i].clear();
  scc = 0;
  cnt = 0;
  for (int i = 1; i <= N; i++) dfn[i] = 0;
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &N, &M);
    init();
    bool win = true;
    for (int i = 1; i <= M; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      if (u == v) continue;
      edges[u].push_back(v);
    }
    for (int i = 1; i <= N; i++)
      if (!dfn[i]) tarjan(i);
    if (scc == 1) win = false;
    if (win) {
      printf("Yes\n");
      int ans1 = Scc[1].size(), ans2 = N - ans1;
      vector<int> a1, a2;
      for (int i = 1; i <= N; i++)
        if (belong[i] == 1)
          a1.push_back(i);
        else
          a2.push_back(i);
      printf("%d %d\n", ans1, ans2);
      for (int i = 0; i < a1.size(); i++) printf("%d ", a1[i]);
      printf("\n");
      for (int i = 0; i < a2.size(); i++) printf("%d ", a2[i]);
      printf("\n");
    } else
      printf("No\n");
  }
}
