#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    vector<vector<int> > graph1(n + 1, vector<int>());
    vector<vector<int> > graph2(n + 1, vector<int>());
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      graph1[a].push_back(b);
      graph2[b].push_back(a);
    }
    vector<bool> checked(n, false);
    bool good = false;
    for (int i = 1; i <= n; i++) {
      if (!checked[i]) {
        checked[i] = true;
        set<int> mens;
        stack<int> st;
        mens.insert(i);
        st.push(i);
        while (!st.empty()) {
          int v = st.top();
          checked[v] = true;
          st.pop();
          for (int u : graph1[v]) {
            if (!mens.count(u)) {
              mens.insert(u);
              st.push(u);
            }
          }
          for (int u : graph1[v]) {
            if (!mens.count(u)) {
              mens.insert(u);
              st.push(u);
            }
          }
        }
        if (mens.size() != n) {
          cout << "Yes\n";
          cout << mens.size() << " " << n - mens.size() << "\n";
          for (int el : mens) {
            cout << el << " ";
          }
          cout << "\n";
          for (int i = 1; i <= n; i++) {
            if (!mens.count(i)) {
              cout << i << " ";
            }
          }
          cout << "\n";
          good = true;
          break;
        }
      }
    }
    if (!good) {
      vector<bool> checked2(n, false);
      for (int i = 1; i <= n; i++) {
        if (!checked2[i]) {
          checked2[i] = true;
          set<int> mens;
          stack<int> st;
          mens.insert(i);
          st.push(i);
          while (!st.empty()) {
            int v = st.top();
            checked2[v] = true;
            st.pop();
            for (int u : graph2[v]) {
              if (!mens.count(u)) {
                mens.insert(u);
                st.push(u);
              }
            }
          }
          if (mens.size() != n) {
            cout << "Yes\n";
            cout << n - mens.size() << " " << mens.size() << "\n";
            for (int i = 1; i <= n; i++) {
              if (!mens.count(i)) {
                cout << i << " ";
              }
            }
            cout << "\n";
            for (int el : mens) {
              cout << el << " ";
            }
            cout << "\n";
            good = true;
            break;
          }
        }
      }
    }
    if (!good) {
      cout << "No\n";
    }
  }
  return 0;
}
