#include <bits/stdc++.h>
using namespace std;
int t, n, m;
int dfn[1000005], low[1000005], s[1000005], cnt, siz, num, fa[1000005],
    tot[1000005];
bool instuck[1000005];
vector<int> G[1000005];
void tarjan(int u) {
  dfn[u] = low[u] = ++cnt;
  s[++siz] = u;
  instuck[u] = 1;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (!dfn[v]) {
      tarjan(v);
      low[u] = min(low[u], low[v]);
    }
    if (instuck[v]) low[u] = min(low[u], low[v]);
  }
  if (dfn[u] == low[u]) {
    num++;
    fa[u] = num;
    instuck[u] = 0;
    tot[num]++;
    while (s[siz] != u) {
      fa[s[siz]] = num;
      instuck[s[siz]] = 0;
      tot[num]++;
      siz--;
    }
    siz--;
  }
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    siz = 0, cnt = 0, num = 0;
    for (int i = 1; i <= n; i++)
      G[i].clear(), tot[i] = 0, instuck[i] = 0, dfn[i] = 0;
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      if (u == v) continue;
      G[u].push_back(v);
    }
    for (int i = 1; i <= n; i++)
      if (!dfn[i]) tarjan(i);
    if (num == 1) {
      printf("NO\n");
      continue;
    }
    printf("YES\n");
    printf("%d %d\n", tot[1], n - tot[1]);
    for (int i = 1; i <= n; i++)
      if (fa[i] == 1) printf("%d ", i);
    printf("\n");
    for (int i = 1; i <= n; i++)
      if (fa[i] != 1) printf("%d ", i);
    printf("\n");
  }
}
