#include <bits/stdc++.h>
using namespace std;
constexpr int kN = int(1E6 + 10);
vector<int> graph[kN];
int dep[kN], low[kN], d[kN], t, p[kN];
bool ins[kN], went[kN];
stack<int> s;
void tarjan(int pos) {
  ins[pos] = went[pos] = true;
  dep[pos] = low[pos] = ++t;
  s.push(pos);
  for (int i : graph[pos]) {
    if (!went[i]) {
      tarjan(i);
      low[pos] = min(low[pos], low[i]);
    } else if (ins[i])
      low[pos] = min(low[pos], low[i]);
  }
  if (low[pos] == dep[pos]) {
    int x;
    do {
      x = s.top();
      p[x] = pos;
      ins[x] = false;
      s.pop();
    } while (x != pos);
  }
  return;
}
void dfs(int pos) {
  went[pos] = true;
  for (int i : graph[pos])
    if (!went[i]) dfs(i);
  return;
}
void solve() {
  int n, m;
  vector<int> X, Y;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) graph[i].clear();
  for (int i = 1, l, r; i <= m; i++) {
    scanf("%d%d", &l, &r);
    if (l != r) graph[l].push_back(r);
  }
  t = 0;
  if (n == 1) {
    printf("No\n");
    return;
  }
  for (int i = 1; i <= n; i++) went[i] = false;
  for (int i = 1; i <= n; i++)
    if (!went[i]) tarjan(i);
  for (int i = 1; i <= n; i++) d[i] = 0;
  for (int i = 1; i <= n; i++)
    for (int j : graph[i])
      if (p[i] != p[j]) d[p[i]]++;
  for (int i = 1; i <= n; i++)
    if (p[i] == i && d[i] == 0) {
      for (int j = 1; j <= n; j++) went[j] = false;
      dfs(i);
      for (int j = 1; j <= n; j++)
        if (went[j])
          X.push_back(j);
        else
          Y.push_back(j);
      break;
    }
  if (!X.empty() && !Y.empty()) {
    printf("Yes\n");
    printf("%d %d\n", int(X.size()), int(Y.size()));
    printf("%d", X[0]);
    for (int i = 1; i < int(X.size()); i++) printf(" %d", X[i]);
    printf("\n");
    printf("%d", Y[0]);
    for (int i = 1; i < int(Y.size()); i++) printf(" %d", Y[i]);
    printf("\n");
  } else
    printf("No\n");
  return;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
}
