#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, m, cnt, found, ans, d[N], num[N], low[N], vis[N];
vector<int> ke[N];
stack<int> S;
void dfs(int u) {
  S.push(u);
  d[u] = 0;
  num[u] = low[u] = ++cnt;
  for (int v : ke[u])
    if (!vis[v]) {
      if (num[v])
        low[u] = min(low[u], num[v]);
      else {
        dfs(v);
        low[u] = min(low[u], low[v]);
      }
    }
  if (num[u] == low[u]) {
    int v;
    do {
      v = S.top();
      S.pop();
      vis[v] = u;
      d[u] += 1;
    } while (u != v);
  }
}
void dfs2(int u) {
  vis[u] = 1;
  ans += 1;
  for (int v : ke[u])
    if (!vis[v]) dfs2(v);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; ++i) {
      int u, v;
      scanf("%d%d", &u, &v);
      ke[u].push_back(v);
    }
    cnt = found = 0;
    for (int i = 1; i <= n; ++i) num[i] = low[i] = vis[i] = 0;
    for (int i = 1; i <= n; ++i)
      if (num[i] == 0) dfs(i);
    for (int u = 1; u <= n; ++u) {
      for (int v : ke[u])
        if (vis[u] != vis[v]) {
          found = v;
          break;
        }
      if (found) break;
    }
    if (!found && d[1] < n) found = 1;
    if (!found)
      puts("No");
    else {
      for (int i = 1; i <= n; ++i) vis[i] = 0;
      ans = 0;
      dfs2(found);
      puts("Yes");
      printf("%d %d\n", ans, n - ans);
      for (int i = 1; i <= n; ++i)
        if (vis[i]) printf("%d ", i);
      puts("");
      for (int i = 1; i <= n; ++i)
        if (!vis[i]) printf("%d ", i);
      puts("");
    }
    for (int i = 1; i <= n; ++i) ke[i].clear();
  }
}
