#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<int> > g, gr;
vector<char> used;
vector<int> order, component, c;
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() {
  int T;
  scanf("%d", &T);
  while (T--) {
    order.clear();
    component.clear();
    scanf("%d %d", &n, &m);
    g = vector<vector<int> >(n);
    gr = vector<vector<int> >(n);
    for (int i = 0; i < m; i++) {
      int a, b;
      scanf("%d %d", &a, &b);
      a--;
      b--;
      g[a].push_back(b);
      gr[b].push_back(a);
    }
    c.assign(n, -1);
    used.assign(n, false);
    for (int i = 0; i < n; ++i)
      if (!used[i]) dfs1(i);
    used.assign(n, false);
    int nc = 0;
    for (int i = 0; i < n; ++i) {
      int v = order[n - 1 - i];
      if (!used[v]) {
        dfs2(v);
        nc++;
        for (int j = 0; j < component.size(); j++) {
          c[component[j]] = i;
        }
        component.clear();
      }
    }
    vector<bool> badC(n, false);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < g[i].size(); j++) {
        if (c[g[i][j]] != c[i]) badC[c[i]] = true;
      }
    }
    int goodC = -1;
    for (int i = 0; i < n; i++) {
      if (!badC[c[i]]) {
        goodC = c[i];
      }
    }
    vector<int> l, r;
    for (int i = 0; i < n; i++) {
      if (c[i] == goodC)
        l.push_back(i);
      else
        r.push_back(i);
    }
    if (nc > 1) {
      printf("YES\n");
      printf("%d %d\n", l.size(), r.size());
      for (int i = 0; i < l.size(); i++) {
        printf("%d ", l[i] + 1);
      }
      printf("\n");
      for (int i = 0; i < r.size(); i++) {
        printf("%d ", r[i] + 1);
      }
      printf("\n");
    } else {
      printf("NO\n");
    }
  }
}
