#include <bits/stdc++.h>
using namespace std;
template <typename T>
T read1() {
  T t = 0;
  bool vis = 0;
  char k;
  do (k = getchar()) == '-' && (vis = 1);
  while ('0' > k || k > '9');
  while ('0' <= k && k <= '9')
    t = (t << 3) + (t << 1) + (k ^ '0'), k = getchar();
  return vis ? -t : t;
}
int s, m, dfn[1000005], low[1000005], cnt, t, bel[1000005];
bool vis[1000005];
vector<int> G[1000005];
stack<int> sta;
long long ans, tans = 1;
void tarjan(int n) {
  dfn[n] = low[n] = ++t;
  sta.push(n);
  vis[n] = 1;
  for (int i = 0; i < G[n].size(); ++i)
    if (!dfn[G[n][i]]) {
      tarjan(G[n][i]);
      low[n] = min(low[n], low[G[n][i]]);
    } else if (vis[G[n][i]])
      low[n] = min(low[n], dfn[G[n][i]]);
  if (dfn[n] == low[n]) {
    ++cnt;
    do {
      n = sta.top();
      vis[n] = 0;
      bel[n] = cnt;
      sta.pop();
    } while (dfn[n] != low[n]);
  }
}
int main() {
  for (int T = read1<long long>(); T--;) {
    s = read1<long long>(), m = read1<long long>();
    while (sta.size()) sta.pop();
    t = 0;
    cnt = 0;
    for (int i = 1; i <= s; ++i) G[i].clear(), vis[i] = dfn[i] = 0;
    for (int i = 1; i <= m; ++i) {
      int u = read1<long long>(), v = read1<long long>();
      G[u].push_back(v);
    }
    for (int i = 1; i <= s; ++i)
      if (!dfn[i]) tarjan(i);
    if (cnt == 1) {
      puts("No");
      continue;
    }
    puts("Yes");
    int t = 0;
    for (int i = 1; i <= s; ++i)
      if (bel[i] == 1) ++t;
    printf("%d %d\n", t, s - t);
    for (int i = 1; i <= s; ++i)
      if (bel[i] == 1) printf("%d ", i);
    putchar('\n');
    for (int i = 1; i <= s; ++i)
      if (bel[i] != 1) printf("%d ", i);
    putchar('\n');
  }
  return 0;
}
