#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
bool b[N];
vector<int> vec1[N], vec2[N];
int n, m;
void init() {
  for (int i = 1; i <= n; i++) b[i] = 0;
}
int cnt = 0;
void dfs1(int x) {
  b[x] = 1;
  cnt++;
  for (auto y : vec1[x]) {
    if (b[y]) continue;
    dfs1(y);
  }
}
void dfs2(int x) {
  b[x] = 1;
  cnt++;
  for (auto y : vec2[x]) {
    if (b[y]) continue;
    dfs2(y);
  }
}
int main() {
  int T;
  scanf("%d", &T);
  for (; T--;) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) vec1[i].clear(), vec2[i].clear();
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      if (u == v) continue;
      vec2[v].push_back(u);
      vec1[u].push_back(v);
    }
    int flag = 0;
    for (int t = 0; t < 10; t++) {
      init();
      int tt = rand() % n + 1;
      cnt = 0;
      dfs1(tt);
      if (cnt != n) {
        flag = 1;
        break;
      }
    }
    if (!flag) {
      for (int t = 0; t < 10; t++) {
        init();
        int tt = rand() % n + 1;
        cnt = 0;
        dfs2(tt);
        if (cnt != n) {
          flag = 2;
          break;
        }
      }
    }
    puts(flag ? "Yes" : "No");
    if (!flag) continue;
    if (flag == 1)
      printf("%d %d\n", cnt, n - cnt);
    else
      printf("%d %d\n", n - cnt, cnt);
    if (flag == 1) {
      for (int i = 1; i <= n; i++)
        if (b[i]) printf("%d ", i);
      puts("");
      for (int i = 1; i <= n; i++)
        if (!b[i]) printf("%d ", i);
      puts("");
    } else {
      for (int i = 1; i <= n; i++)
        if (!b[i]) printf("%d ", i);
      puts("");
      for (int i = 1; i <= n; i++)
        if (b[i]) printf("%d ", i);
      puts("");
    }
  }
}
