#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
long long int powmod(long long int a, long long int b) {
  long long int res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int nxt() {
  int x;
  cin >> x;
  return x;
}
vector<vector<int> > g, gr;
vector<bool> used;
vector<int> order, component;
void dfs1(int v) {
  used[v] = true;
  for (size_t i = 0; i < g[v].size(); ++i)
    if (!used[g[v][i]]) dfs1(g[v][i]);
  order.push_back(v);
}
void dfs2(int v) {
  used[v] = true;
  component.push_back(v);
  for (size_t i = 0; i < gr[v].size(); ++i)
    if (!used[gr[v][i]]) dfs2(gr[v][i]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tc = nxt();
  while (tc--) {
    int n = nxt(), m = nxt();
    g.assign(n, vector<int>());
    gr.assign(n, vector<int>());
    order.clear();
    component.clear();
    for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m));
         i += 1 - 2 * ((0) > (m))) {
      int x = nxt(), y = nxt();
      x--, y--;
      if (x == y) continue;
      g[x].push_back(y);
      gr[y].push_back(x);
    }
    used.assign(n, 0);
    for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
         i += 1 - 2 * ((0) > (n))) {
      if (!used[i]) dfs1(i);
    }
    used.assign(n, 0);
    set<int> ans;
    int numscc = 0;
    for (int i = 0; i < n; ++i) {
      int v = order[n - 1 - i];
      if (!used[v]) {
        component.clear();
        dfs2(v);
        numscc++;
      }
    }
    if (numscc != 1) {
      puts("Yes");
      for (int x : component) ans.insert(x);
      printf("%d %d\n", (int)ans.size(), (int)n - ans.size());
      for (int x : ans) printf("%d ", x + 1);
      puts("");
      for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
           i += 1 - 2 * ((0) > (n)))
        if (ans.count(i) == 0) printf("%d ", i + 1);
      puts("");
    } else
      puts("No");
  }
  return 0;
}
