#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000010;
int t, n, m, x, y;
vector<bool> assign(MAX);
int jnum, cnum;
vector<vector<int>> htoc(MAX);
vector<vector<int>> ctoh(MAX);
void dfs(int id) {
  assign[id] = true;
  jnum++;
  for (int& x : htoc[id]) {
    if (!assign[x]) dfs(x);
  }
}
void dfs2(int id) {
  assign[id] = true;
  cnum++;
  for (int& x : ctoh[id]) {
    if (!assign[x]) dfs2(x);
  }
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) {
      assign[i] = false;
      htoc[i].clear();
      ctoh[i].clear();
    }
    while (m--) {
      scanf("%d%d", &x, &y);
      if (x != y) {
        htoc[x].push_back(y);
        ctoh[y].push_back(x);
      }
    }
    jnum = 0;
    dfs(1);
    if (jnum < n) {
      cout << "Yes" << endl << jnum << " " << n - jnum << endl;
      for (int j = 1; j <= n; ++j)
        if (assign[j]) cout << j << " ";
      cout << endl;
      for (int c = 1; c <= n; ++c)
        if (!assign[c]) cout << c << " ";
      cout << endl;
      continue;
    }
    cnum = 0;
    for (int i = 1; i <= n; ++i) assign[i] = false;
    dfs2(1);
    if (cnum < n) {
      cout << "Yes" << endl << n - cnum << " " << cnum << endl;
      for (int j = 1; j <= n; ++j)
        if (!assign[j]) cout << j << " ";
      cout << endl;
      for (int c = 1; c <= n; ++c)
        if (assign[c]) cout << c << " ";
      cout << endl;
      continue;
    }
    cout << "No" << endl;
  }
  return 0;
}
