#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > humans;
vector<vector<int> > cats;
vector<int> p;
void dfs(int t) {
  p[t] = 1;
  for (auto i : humans[t]) {
    if (p[i] == 0) {
      dfs(i);
    }
  }
}
void dfsc(int t) {
  p[t] = -1;
  for (auto i : cats[t]) {
    if (p[i] == 0) {
      dfsc(i);
    }
  }
}
int main() {
  int t;
  scanf("%d", &t);
  int n, m;
  int u, v;
  bool can;
  int h;
  while (t--) {
    scanf("%d %d", &n, &m);
    humans.resize(n);
    cats.resize(n);
    p.resize(n);
    can = false;
    h = 0;
    for (int i = 0; i < m; i++) {
      scanf("%d %d", &u, &v);
      humans[u - 1].push_back(v - 1);
      cats[v - 1].push_back(u - 1);
    }
    dfs(0);
    for (int i = 0; i < n; i++) {
      if (p[i] != 1) {
        can = true;
        p[i] = -1;
      } else {
        h++;
      }
    }
    if (!can) {
      p.clear();
      p.resize(n);
      dfsc(0);
      h = n;
      for (int i = 0; i < n; i++) {
        if (p[i] != -1) {
          can = true;
          p[i] = 1;
        } else {
          h--;
        }
      }
    }
    if (n == 1) {
      printf("No\n");
    } else {
      if (can) {
        printf("Yes\n");
        printf("%d %d\n", h, n - h);
        for (int i = 0; i < n; i++) {
          if (p[i] == 1) {
            printf("%d ", i + 1);
          }
        }
        printf("\n");
        for (int i = 0; i < n; i++) {
          if (p[i] != 1) {
            printf("%d ", i + 1);
          }
        }
        printf("\n");
      } else {
        printf("No\n");
      }
    }
    humans.clear();
    cats.clear();
    p.clear();
  }
  return 0;
}
