#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class C>
void mini(C &a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C &a4, C b4) {
  a4 = max(a4, b4);
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V) os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
struct SSS {
  vector<vector<long long>> d, drev;
  vector<long long> ord, ss, cz;
  long long is, n;
  SSS(long long _n) : n(_n) {
    d.resize(n);
    drev.resize(n);
    cz.resize(n);
    ss.resize(n, -1);
  }
  void add_edge(long long a, long long b) {
    d[a].push_back(b);
    drev[b].push_back(a);
  }
  void dfs(long long nr) {
    if (cz[nr]) return;
    cz[nr] = 1;
    for (long long ak : d[nr]) dfs(ak);
    ord.push_back(nr);
  }
  void dfs2(long long nr, long long s) {
    if (ss[nr] != -1) return;
    ss[nr] = s;
    for (long long ak : drev[nr]) dfs2(ak, s);
  }
  void licz() {
    for (long long i = (0); i <= ((long long)(n)-1); i++) dfs(i);
    is = 0;
    reverse((ord).begin(), (ord).end());
    for (long long el : ord) {
      if (ss[el] == -1) {
        dfs2(el, is);
        is++;
      }
    }
  }
  vector<vector<long long>> stworzgraf() {
    vector<vector<long long>> res(is);
    for (long long i = (0); i <= ((long long)(n)-1); i++)
      for (long long ak : d[i]) {
        if (ss[i] != ss[ak]) res[ss[i]].push_back(ss[ak]);
      }
    for (auto &el : res) {
      sort((el).begin(), (el).end());
      el.resize(unique((el).begin(), (el).end()) - el.begin());
    }
    return res;
  }
};
struct Sol {
  long long n, m;
  void run() {
    cin >> n >> m;
    SSS ss(n);
    for (long long i = (0); i <= ((long long)(m)-1); i++) {
      long long a, b;
      cin >> a >> b;
      a--;
      b--;
      if (a != b) {
        ss.add_edge(a, b);
      }
    }
    ss.licz();
    if (ss.is == 1) {
      cout << "No\n";
    } else {
      vector<long long> res1, res2;
      for (long long i = (0); i <= ((long long)(n)-1); i++) {
        if (ss.ss[i] == 0) {
          res1.push_back(i);
        } else {
          res2.push_back(i);
        }
      }
      swap(res1, res2);
      cout << "Yes\n";
      cout << ((long long)(res1).size()) << " " << ((long long)(res2).size())
           << "\n";
      for (long long el : res1) {
        cout << el + 1 << " ";
      }
      cout << "\n";
      for (long long el : res2) {
        cout << el + 1 << " ";
      }
      cout << "\n";
    }
  }
};
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  if (0) cout << fixed << setprecision(6);
  long long t;
  cin >> t;
  while (t--) {
    Sol sol;
    sol.run();
  }
}
