#include <bits/stdc++.h>
using namespace std;
void print(vector<int> X) {
  for (int i = 0; i < X.size(); i++) {
    cout << X[i] << " ";
  }
  cout << endl;
  return;
}
void solve(vector<set<int>> &A, vector<set<int>> &B, int i, vector<int> &A1,
           vector<int> &B1, int a) {
  queue<int> Q1;
  queue<int> Q2;
  Q1.push(i);
  A1[i] = a;
  while (!Q1.empty()) {
    int x = Q1.front();
    Q1.pop();
    for (int y : A[i]) {
      if (B1[y] == 0) {
        Q2.push(y);
        B1[y] = a;
      }
    }
    while (!Q2.empty()) {
      x = Q2.front();
      Q2.pop();
      B1[x] = a;
      for (int y : B[x]) {
        if (A1[y] == 0) {
          A1[y] = a;
          Q1.push(y);
        }
      }
    }
  }
  return;
}
void dfs(vector<set<int>> &A, set<int> &X, vector<int> &Y, int a) {
  for (int b : A[a]) {
    if (Y[b] == 0) {
      Y[b] = 1;
      X.insert(b);
      dfs(A, X, Y, b);
    }
  }
  return;
}
void sp(set<int> &X, int n, int x) {
  cout << "Yes" << endl;
  cout << x << " " << n - x << endl;
  for (int y : X) {
    cout << y << " ";
  }
  cout << endl;
  for (int i = 1; i <= n; i++) {
    if (X.find(i) == X.end()) {
      cout << i << " ";
    }
  }
  cout << endl;
  return;
}
void sp1(set<int> &X, int n, int x) {
  cout << "Yes" << endl;
  cout << n - x << " " << x << endl;
  for (int i = 1; i <= n; i++) {
    if (X.find(i) == X.end()) {
      cout << i << " ";
    }
  }
  cout << endl;
  for (int y : X) {
    cout << y << " ";
  }
  cout << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  for (int t = 0; t < T; t++) {
    int n, m;
    cin >> n >> m;
    vector<set<int>> A(n + 1);
    vector<set<int>> B(n + 1);
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      if (a != b) {
        A[a].insert(b);
        B[b].insert(a);
      }
    }
    set<int> X;
    vector<int> Y(n + 1, 0);
    Y[1] = 1;
    X.insert(1);
    dfs(A, X, Y, 1);
    set<int> X1;
    vector<int> Y1(n + 1, 0);
    Y1[1] = 1;
    X1.insert(1);
    dfs(B, X1, Y1, 1);
    int x = X.size();
    int y = X1.size();
    if (x == n) {
      if (y == n || y == 0) {
        cout << "No" << endl;
      } else {
        sp1(X1, n, y);
      }
    } else {
      sp(X, n, x);
    }
  }
  return 0;
}
