#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6;
vector<int> g[MAXN + 10];
int n, m, t;
bool v[MAXN + 10], s[MAXN + 10];
int in[MAXN + 10], low[MAXN + 10], out[MAXN + 10], ind;
int B[MAXN + 10];
stack<int> S;
int scc;
void tarjan(int cur) {
  low[cur] = in[cur] = ind++;
  S.push(cur);
  s[cur] = true;
  v[cur] = true;
  for (int i = 0; i < (int)g[cur].size(); i++) {
    int next = g[cur][i];
    if (!v[next]) {
      tarjan(next);
      low[cur] = min(low[cur], low[next]);
    } else if (s[next])
      low[cur] = min(low[cur], in[next]);
  }
  if (low[cur] == in[cur]) {
    while (true) {
      int node = S.top();
      S.pop();
      s[node] = false;
      B[node] = scc;
      if (node == cur) break;
    }
    scc++;
  }
}
void init() {
  for (int i = 0; i <= n; i++) {
    v[i] = s[i] = false;
    g[i].clear();
    low[i] = in[i] = 0;
    out[i] = 0;
  }
  scc = ind = 0;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &n, &m);
    init();
    for (int i = 0; i < m; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      if (x == y) continue;
      g[x].push_back(y);
    }
    for (int i = 1; i <= n; i++) {
      if (!v[i]) tarjan(i);
    }
    if (scc == 1) {
      printf("No\n");
    } else {
      printf("Yes\n");
      for (int i = 1; i <= n; i++) {
        for (int j = 0; j < (int)g[i].size(); j++) {
          int x = B[i], y = B[g[i][j]];
          if (x == y) continue;
          out[x]++;
        }
      }
      int sc = -1;
      for (int i = 0; i < scc && sc == -1; i++) {
        if (!out[i]) sc = i;
      }
      int res = 0;
      for (int i = 1; i <= n; i++) res += B[i] == sc;
      printf("%d %d\n", res, n - res);
      for (int i = 1; i <= n; i++)
        if (B[i] == sc) printf("%d ", i);
      printf("\n");
      for (int i = 1; i <= n; i++)
        if (B[i] != sc) printf("%d ", i);
      printf("\n");
    }
  }
  return 0;
}
