#include <bits/stdc++.h>
using namespace std;
int dfs(int u, vector<int> gr[], vector<bool> &vis, vector<bool> &ans) {
  int cnt = 1;
  ans[u] = vis[u] = true;
  for (auto v : gr[u])
    if (not vis[v]) {
      cnt += dfs(v, gr, vis, ans);
    }
  return cnt;
}
void print(vector<bool> &ans, bool judge) {
  int n = ans.size();
  vector<int> jud, cat;
  for (int i = 1; i < n; i++) {
    if (judge)
      ans[i] ? jud.push_back(i) : cat.push_back(i);
    else
      ans[i] ? cat.push_back(i) : jud.push_back(i);
  }
  cout << "Yes"
       << "\n";
  cout << jud.size() << " " << cat.size() << "\n";
  for (auto x : jud) cout << x << " ";
  cout << "\n";
  for (auto x : cat) cout << x << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    n++;
    vector<bool> vis1(n), vis2(n), ans1(n), ans2(n);
    vector<int> gr1[n], gr2[n];
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      gr1[a].push_back(b);
      gr2[b].push_back(a);
    }
    int x;
    n--;
    x = dfs(1, gr1, vis1, ans1);
    if (x != n) {
      print(ans1, true);
      continue;
    }
    x = dfs(1, gr2, vis2, ans2);
    if (x != n) {
      print(ans2, false);
      continue;
    }
    cout << "No"
         << "\n";
  }
}
