#include <bits/stdc++.h>
struct Scanner {
  static const int SIZE = 1 << 16;
  int pos = 0;
  int size = 0;
  int ch = -1;
  char b[SIZE];
  void next() {
    if (pos == size) {
      size = fread(b, 1, SIZE, stdin);
      pos = 0;
    }
    ch = b[pos++];
  }
  int nextInt() {
    while (ch <= 32) next();
    int res = 0;
    while ('0' <= ch && ch <= '9') {
      res = res * 10 + ch - '0';
      next();
    }
    return res;
  }
};
struct Writer {
  static const int SIZE = 1 << 16;
  int pos = 0;
  char b[SIZE];
  void put(char c) {
    if (pos == SIZE) {
      fwrite(b, 1, SIZE, stdout);
      pos = 0;
    }
    b[pos++] = c;
  }
  void flush() { fwrite(b, 1, pos, stdout); }
  void printInt(int x) {
    char num[10];
    int di = 0;
    do {
      num[di++] = '0' + x % 10;
      x /= 10;
    } while (x > 0);
    while (di > 0) {
      put(num[--di]);
    }
  }
};
Scanner in;
Writer out;
struct P {
  int ind;
  int nextInd;
};
const int N = 1e6 + 1;
P stk[N];
int sp;
void findOrd(int cur, std::vector<bool>& used,
             std::vector<std::vector<int>>& next, std::vector<int>& outOrd) {
  sp = 0;
  stk[sp++] = P{cur, 0};
  while (sp > 0) {
    P& cur = stk[sp - 1];
    used[cur.ind] = true;
    int i = cur.nextInd;
    while (i < next[cur.ind].size() && used[next[cur.ind][i]]) {
      ++i;
    }
    cur.nextInd = i;
    if (i < next[cur.ind].size()) {
      stk[sp++] = P{next[cur.ind][i], 0};
    } else {
      outOrd.push_back(cur.ind);
      sp--;
    }
  }
}
void collect(int cur, std::vector<bool>& used,
             std::vector<std::vector<int>>& next, std::vector<int>& cont) {
  used[cur] = true;
  cont.push_back(cur);
  for (int v : next[cur]) {
    if (!used[v]) {
      collect(v, used, next, cont);
    }
  }
}
void print(std::vector<int>& v) {
  int i = 0;
  for (int x : v) {
    out.printInt(++x);
    out.put(' ');
  }
  out.put('\n');
}
void solve() {
  int nv = in.nextInt();
  int ne = in.nextInt();
  nv *= 2;
  std::vector<std::vector<int>> next(nv);
  for (int i = 0; i < ne; ++i) {
    int a = in.nextInt();
    int b = in.nextInt();
    --a;
    --b;
    next[a].push_back(b + nv / 2);
    if (a == b) {
      next[b + nv / 2].push_back(a);
    }
  }
  std::vector<bool> used(nv);
  std::vector<int> outOrd;
  for (int i = 0; i < nv; ++i) {
    if (!used[i]) findOrd(i, used, next, outOrd);
  }
  std::reverse(outOrd.begin(), outOrd.end());
  std::vector<std::vector<int>> revNext(nv);
  for (int i = 0; i < nv; ++i) {
    for (int v : next[i]) {
      revNext[v].push_back(i);
    }
  }
  used.assign(nv, false);
  std::vector<std::vector<int>> comps;
  for (int i = 0; i < nv; ++i) {
    if (!used[outOrd[i]]) {
      std::vector<int> comp;
      findOrd(outOrd[i], used, revNext, comp);
      comps.push_back(comp);
    }
  }
  if (comps.size() <= 1) {
    out.put('N');
    out.put('o');
    out.put('\n');
    return;
  }
  std::vector<int> p, j;
  for (int i = 0; i < (int)comps[0].size(); ++i) {
    if (comps[0][i] >= nv / 2) {
      p.push_back(comps[0][i] - nv / 2);
    }
  }
  for (int i = 1; i < (int)comps.size(); ++i) {
    for (int v : comps[i]) {
      if (v < nv / 2) {
        j.push_back(v);
      }
    }
  }
  assert(p.size() + j.size() == nv / 2);
  out.put('Y');
  out.put('e');
  out.put('s');
  out.put('\n');
  out.printInt(j.size());
  out.put(' ');
  out.printInt(p.size());
  out.put('\n');
  print(j);
  print(p);
}
int main() {
  int nt = in.nextInt();
  while (nt--) {
    solve();
  }
  out.flush();
  return 0;
}
