#include <bits/stdc++.h>
using namespace std;
vector<int> v[2 * 1000010], sol[2 * 1000010];
int f[2 * 1000010], ok = 1, apart[2 * 1000010];
void dfs(int nod, int n, int cc) {
  int i, vecin;
  f[nod] = 1;
  sol[cc].push_back(nod);
  for (i = 0; i < v[nod].size(); i++) {
    vecin = v[nod][i];
    if (!f[vecin - n]) dfs(vecin - n, n, cc);
  }
}
void dfs2(int nod, int n, int cc) {
  int i, vecin;
  f[nod] = 1;
  sol[cc].push_back(nod - n);
  for (i = 0; i < v[nod].size(); i++) {
    vecin = v[nod][i];
    if (!f[vecin + n]) dfs2(vecin + n, n, cc);
  }
}
int main() {
  FILE *fin = stdin;
  FILE *fout = stdout;
  int t, n, m, i, j, x, y, cc, om;
  fscanf(fin, "%d", &t);
  for (; t; t--) {
    fscanf(fin, "%d%d", &n, &m);
    for (i = 1; i <= n; i++) {
      v[i].clear();
      v[n + i].clear();
      sol[i].clear();
      sol[n + i].clear();
      f[i] = f[n + i] = 0;
    }
    for (i = 1; i <= m; i++) {
      fscanf(fin, "%d%d", &x, &y);
      v[x].push_back(n + y);
      v[n + y].push_back(x);
    }
    cc = 0;
    for (i = 1; i <= n; i++) {
      if (!f[i]) {
        dfs(i, n, ++cc);
      }
    }
    if (cc == 1) {
      for (i = 1; i <= 2 * n; i++) {
        f[i] = 0;
        sol[i].clear();
      }
      cc = 0;
      for (i = n + 1; i <= 2 * n; i++) {
        if (!f[i]) {
          dfs2(i, n, ++cc);
        }
      }
      if (cc == 1)
        fprintf(fout, "No\n");
      else {
        fprintf(fout, "Yes\n");
        om = sol[cc].size();
        fprintf(fout, "%d %d\n", om, n - om);
        for (j = 0; j < sol[cc].size(); j++) fprintf(fout, "%d ", sol[cc][j]);
        fprintf(fout, "\n");
        for (i = 1; i < cc; i++) {
          for (j = 0; j < sol[i].size(); j++) fprintf(fout, "%d ", sol[i][j]);
        }
        fprintf(fout, "\n");
      }
    } else {
      fprintf(fout, "Yes\n");
      om = 0;
      for (i = 1; i < cc; i++) {
        om += sol[i].size();
      }
      fprintf(fout, "%d %d\n", om, n - om);
      for (i = 1; i < cc; i++) {
        for (j = 0; j < sol[i].size(); j++) fprintf(fout, "%d ", sol[i][j]);
      }
      fprintf(fout, "\n");
      for (j = 0; j < sol[cc].size(); j++) fprintf(fout, "%d ", sol[cc][j]);
      fprintf(fout, "\n");
    }
  }
  return 0;
}
