#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 1e18;
const int MOD = 1e9 + 7;
const int MAXN = 2e6 + 5;
vector<int> G[MAXN];
vector<int> GR[MAXN];
int vist[MAXN];
int color[MAXN];
int n, m;
stack<int> s;
void dfs(int v) {
  if (vist[v]) return;
  vist[v] = 1;
  for (int u : GR[v]) dfs(u);
  s.push(v);
}
void assign(int v, int c) {
  if (color[v] != -1) return;
  color[v] = c;
  for (int u : G[v]) assign(u, c);
}
int main() {
  memset(color, -1, sizeof(color));
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n), scanf("%d", &m);
    for (int i = 0; i < (int)m; i++) {
      int u, v;
      scanf("%d", &u), scanf("%d", &v);
      u--, v--;
      if (u != v) G[u].push_back(v);
      if (u != v) GR[v].push_back(u);
    }
    for (int i = 0; i < (int)n; i++) dfs(i);
    int cmp = 0;
    while (!s.empty()) {
      int v = s.top();
      s.pop();
      if (color[v] == -1) assign(v, cmp >= 1 ? 1 : 0), cmp++;
    }
    if (cmp > 1) {
      printf("Yes\n");
      int j = 0, p = 0;
      for (int i = 0; i < (int)n; i++) j += color[i];
      p = n - j;
      printf("%d %d\n", p, j);
      for (int i = 0; i < (int)n; i++)
        if (!color[i]) printf("%d ", i + 1);
      printf("\n");
      for (int i = 0; i < (int)n; i++)
        if (color[i]) printf("%d ", i + 1);
      printf("\n");
    } else
      printf("No\n");
    for (int i = 0; i < (int)n; i++)
      G[i].clear(), GR[i].clear(), color[i] = -1, vist[i] = false;
  }
  return 0;
}
