#include <bits/stdc++.h>
using namespace std;
int N, M;
int timew, cnt;
stack<int> si;
int low[2000005], dep[2000005], siz[2000005], dfn[2000005], nex[2000005],
    las[2000005], Arrive[2000005], st[2000005], cnt1;
bool isin[2000005];
void jt(int xx, int yy) {
  cnt++;
  nex[cnt] = las[xx];
  las[xx] = cnt;
  Arrive[cnt] = yy;
}
void tarjan(int noww) {
  timew++;
  low[noww] = dfn[noww] = timew;
  si.push(noww);
  isin[noww] = true;
  for (int i = las[noww]; i; i = nex[i]) {
    if (!dfn[Arrive[i]]) {
      tarjan(Arrive[i]);
      low[noww] = min(low[noww], low[Arrive[i]]);
    } else if (isin[Arrive[i]])
      low[noww] = min(low[noww], dfn[Arrive[i]]);
  }
  if (low[noww] == dfn[noww]) {
    cnt1++;
    int k = -1;
    while (k != noww) {
      k = si.top();
      si.pop();
      isin[k] = false;
      st[k] = cnt1;
      siz[cnt1]++;
    }
  }
}
void Clear() {
  cnt = 0;
  cnt1 = 0;
  timew = 0;
  for (int i = 1; i <= N; i++)
    las[i] = dep[i] = st[i] = siz[i] = dfn[i] = low[i] = dep[i] = 0;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &N, &M);
    Clear();
    for (int i = 1; i <= M; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      if (u != v) jt(u, v);
    }
    for (int i = 1; i <= N; i++)
      if (!dfn[i]) tarjan(i);
    if (siz[st[1]] == N) {
      puts("No");
      continue;
    }
    for (int i = 1; i <= N; i++)
      for (int j = las[i]; j; j = nex[j])
        if (st[i] != st[Arrive[j]]) dep[st[i]]++;
    bool flag = false;
    for (int i = 1; i <= cnt1; i++) {
      if (!dep[i] && siz[i]) {
        flag = true;
        puts("Yes");
        vector<int> ans[2];
        for (int j = 1; j <= N; j++) ans[st[j] == i].push_back(j);
        printf("%d %d\n", ans[1].size(), ans[0].size());
        for (auto &i : ans[1]) printf("%d ", i);
        cout << '\n';
        for (auto &i : ans[0]) printf("%d ", i);
        cout << '\n';
        break;
      }
    }
    if (!flag) puts("No");
  }
  return 0;
}
