/*Program from Luvwgyx*/
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long
#define fir first
#define sec second
#define pi pair<ll ,int >
#define mp(x,y) make_pair(x,y)
#define sqr(x) ((x)*(x))
using namespace std;
const int maxn=1e6+10;
int n,m,cnt;bool vis[maxn];
vector<int >e1[maxn],e2[maxn];
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(int x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
void write(int x){print(x);puts("");}
void init(){
    cnt=0;memset(vis,0,sizeof(vis));
    for(int i=0;i<maxn;i++)e1[i].clear(),e2[i].clear();
}
void dfs1(int x){
    vis[x]=1;cnt++;
    for(int i=0;i<(int)e1[x].size();i++)
        if(!vis[e1[x][i]])dfs1(e1[x][i]);
}
void dfs2(int x){
    vis[x]=1;cnt++;
    for(int i=0;i<(int)e2[x].size();i++)
        if(!vis[e2[x][i]])dfs2(e2[x][i]);
}
signed main(){
    int T=read();
    while(T--){
        n=read();m=read();init();
        for(int i=1;i<=m;i++){
            int u=read(),v=read();
            e1[u].push_back(v);e2[v].push_back(u);
        }dfs1(1);bool flag=1;
        if(cnt==n){
            cnt=0;memset(vis,0,sizeof(vis));dfs2(1);
            if(cnt==n){puts("No");continue;}
            cnt=n-cnt;flag=0;
        }printf("Yes\n%lld %lld\n",cnt,n-cnt);
        for(int i=1;i<=n;i++)if(vis[i]==flag)printf("%lld ",i);puts("");
        for(int i=1;i<=n;i++)if(vis[i]!=flag)printf("%lld ",i);puts("");
    }
    return 0;
}


/*Program from Luvwgyx*/
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
//#define int long long
#define fir first
#define sec second
#define pi pair<ll ,int >
#define mp(x,y) make_pair(x,y)
#define sqr(x) ((x)*(x))
using namespace std;
const int maxn=1e6+10;
struct node{int to,nxt;}e[2][maxn<<1];
int n,m,cnt,tot[2],head[2][maxn];bool vis[maxn];
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(int x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
void write(int x){print(x);puts("");}
void init(){
    cnt=tot[0]=tot[1]=0;
    for(int i=1;i<=n;i++)vis[i]=0;
    for(int i=1;i<=n;i++)head[0][i]=head[1][i]=0;
}
void add(int opt,int u,int v){e[opt][++tot[opt]].to=v;e[opt][tot[opt]].nxt=head[opt][u];head[opt][u]=tot[opt];}
void dfs(int opt,int x){
    vis[x]=1;cnt++;
    for(int i=head[opt][x],v=e[opt][i].to;i;i=e[opt][i].nxt,v=e[opt][i].to)
        if(!vis[v])dfs(opt,v);
}
signed main(){
    int T=read();
    while(T--){
        n=read();m=read();init();
        for(int i=1;i<=m;i++){
            int u=read(),v=read();
            add(0,u,v);add(1,v,u);
        }dfs(0,1);bool flag=1;
        if(cnt==n){
            cnt=0;for(int i=1;i<=n;i++)vis[i]=0;dfs(1,1);
            if(cnt==n){puts("No");continue;}cnt=n-cnt;flag=0;
        }printf("Yes\n%d %d\n",cnt,n-cnt);
        for(int i=1;i<=n;i++)if(vis[i]==flag)printf("%d ",i);puts("");
        for(int i=1;i<=n;i++)if(vis[i]!=flag)printf("%d ",i);puts("");
    }
    return 0;
}


/*Program from Luvwgyx*/
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
//#define int long long
#define fir first
#define sec second
#define pi pair<ll ,int >
#define mp(x,y) make_pair(x,y)
#define sqr(x) ((x)*(x))
using namespace std;
const int maxn=1e6+10;
struct node{int to,nxt;}e[2][maxn<<1];
int n,m,cnt,tot[2],head[2][maxn];bool vis[maxn];
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(int x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
void write(int x){print(x);puts("");}
void init(){
    cnt=tot[0]=tot[1]=0;
    memset(vis,0,sizeof(vis));
    memset(head,0,sizeof(head));
}
void add(int opt,int u,int v){e[opt][++tot[opt]].to=v;e[opt][tot[opt]].nxt=head[opt][u];head[opt][u]=tot[opt];}
void dfs(int opt,int x){
    vis[x]=1;cnt++;
    for(int i=head[opt][x],v=e[opt][i].to;i;i=e[opt][i].nxt,v=e[opt][i].to)
        if(!vis[v])dfs(opt,v);
}
signed main(){
    //int T=read();
    int T;scanf("%d",&T);
    while(T--){
        //n=read();m=read();
        scanf("%d%d",&n,&m);
        init();
        for(int i=1;i<=m;i++){
            //int u=read(),v=read();
            int u,v;scanf("%d%d",&u,&v);
            add(0,u,v);add(1,v,u);
        }dfs(0,1);bool flag=1;
        if(cnt==n){
            cnt=0;memset(vis,0,sizeof(vis));dfs(1,1);
            if(cnt==n){puts("No");continue;}cnt=n-cnt;flag=0;
        }printf("Yes\n%d %d\n",cnt,n-cnt);
        for(int i=1;i<=n;i++)if(vis[i]==flag)printf("%d ",i);puts("");
        for(int i=1;i<=n;i++)if(vis[i]!=flag)printf("%d ",i);puts("");
    }
    return 0;
}


/*Program from Luvwgyx*/
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long
#define fir first
#define sec second
#define pi pair<ll ,int >
#define mp(x,y) make_pair(x,y)
#define sqr(x) ((x)*(x))
using namespace std;
const int maxn=1e6+10;
struct node{int to,nxt;}e[2][maxn<<1];
int n,m,cnt,tot[2],head[2][maxn];bool vis[maxn];
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(int x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
void write(int x){print(x);puts("");}
void init(){
    cnt=tot[0]=tot[1]=0;
    memset(vis,0,sizeof(vis));
    memset(head,0,sizeof(head));
}
void add(int opt,int u,int v){e[opt][++tot[opt]].to=v;e[opt][tot[opt]].nxt=head[opt][u];head[opt][u]=tot[opt];}
void dfs(int opt,int x){
    vis[x]=1;cnt++;
    for(int i=head[opt][x],v=e[opt][i].to;i;i=e[opt][i].nxt,v=e[opt][i].to)
        if(!vis[v])dfs(opt,v);
}
signed main(){
    int T=read();
    while(T--){
        n=read();m=read();init();
        for(int i=1;i<=m;i++){
            int u=read(),v=read();
            add(0,u,v);add(1,v,u);
        }dfs(0,1);bool flag=1;
        if(cnt==n){
            cnt=0;memset(vis,0,sizeof(vis));dfs(1,1);
            if(cnt==n){puts("No");continue;}
            cnt=n-cnt;flag=0;
        }printf("Yes\n%lld %lld\n",cnt,n-cnt);
        for(int i=1;i<=n;i++)if(vis[i]==flag)printf("%lld ",i);puts("");
        for(int i=1;i<=n;i++)if(vis[i]!=flag)printf("%lld ",i);puts("");
    }
    return 0;
}


/*Program from Luvwgyx*/
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
//#define int long long
#define fir first
#define sec second
#define pi pair<ll ,int >
#define mp(x,y) make_pair(x,y)
#define sqr(x) ((x)*(x))
using namespace std;
const int maxn=1e6+10;
struct node{int to,nxt;}e[2][maxn<<1];
int n,m,cnt,tot[2],head[2][maxn];bool vis[maxn];
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(int x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
void write(int x){print(x);puts("");}
void init(){
    cnt=tot[0]=tot[1]=0;
    memset(vis,0,sizeof(vis));
    memset(head,0,sizeof(head));
}
void add(int opt,int u,int v){e[opt][++tot[opt]].to=v;e[opt][tot[opt]].nxt=head[opt][u];head[opt][u]=tot[opt];}
void dfs(int opt,int x){
    vis[x]=1;cnt++;
    for(int i=head[opt][x],v=e[opt][i].to;i;i=e[opt][i].nxt,v=e[opt][i].to)
        if(!vis[v])dfs(opt,v);
}
signed main(){
    int T=read();
    while(T--){
        n=read();m=read();init();
        for(int i=1;i<=m;i++){
            int u=read(),v=read();
            add(0,u,v);add(1,v,u);
        }dfs(0,1);bool flag=1;
        if(cnt==n){
            cnt=0;memset(vis,0,sizeof(vis));dfs(1,1);
            if(cnt==n){puts("No");continue;}
            cnt=n-cnt;flag=0;
        }printf("Yes\n%d %d\n",cnt,n-cnt);
        for(int i=1;i<=n;i++)if(vis[i]==flag)printf("%d ",i);puts("");
        for(int i=1;i<=n;i++)if(vis[i]!=flag)printf("%d ",i);puts("");
    }
    return 0;
}


#include <bits/stdc++.h>
#define rep(i, a, b) for(int i(a), i##_ORZ(b); i <= i##_ORZ; i++)
#define drep(i, a, b) for(int i(a), i##_ORZ(b); i >= i##_ORZ; i--)
using namespace std;
const int maxn = 4000010;
int n, m, head[maxn], ver[maxn], Next[maxn], tot;
int dfn[maxn], low[maxn], num, scc, bel[maxn], ins[maxn], top, sta[maxn];
void add(int x, int y) { ver[++tot] = y, Next[tot] = head[x], head[x] = tot; }
void tarjan(int x) {
	dfn[x] = low[x] = ++num;
	sta[++top] = x; ins[x] = 1;
	for(int i = head[x]; i; i = Next[i])
		if(!dfn[ver[i]]) tarjan(ver[i]), low[x] = min(low[x], low[ver[i]]);
		else if(ins[ver[i]]) low[x] = min(low[x], dfn[ver[i]]);
	if(dfn[x] == low[x]) {
		scc++; int z = 0;
		while(z != x) {
			z = sta[top--], ins[z] = 0, bel[z] = scc;
		}
	}
}
void clear() {
	rep(i, 1, n) head[i] = dfn[i] = low[i] = bel[i] = ins[i] = 0;
	top = num = scc = tot = 0;
}
int main() {
	int T; scanf("%d", &T);
	while(T--) {
		scanf("%d%d", &n, &m);
		rep(i, 1, m) {
			int x, y;
			scanf("%d%d", &x, &y);
			add(x, y);
		}
		rep(i, 1, n) if(!dfn[i]) tarjan(i);
		if(scc == 1) printf("No\n");
		else {
			printf("Yes\n");
			int cnt = 0;
			rep(i, 1, n) if(bel[i] == 1) cnt++;
			printf("%d %d\n", cnt, n - cnt);
			rep(i, 1, n) if(bel[i] == 1) printf("%d ", i);
			printf("\n");
			rep(i, 1, n) if(bel[i] != 1) printf("%d ", i);
			printf("\n");
		}
		clear();
	}
	return 0;
}


#include <bits/stdc++.h>
#define rep(i, a, b) for(int i(a), i##_ORZ(b); i <= i##_ORZ; i++)
#define drep(i, a, b) for(int i(a), i##_ORZ(b); i >= i##_ORZ; i--)
using namespace std;
const int maxn = 100010;
int n, m, head[maxn], ver[maxn], Next[maxn], tot;
int dfn[maxn], low[maxn], num, scc, bel[maxn], ins[maxn], top, sta[maxn];
void add(int x, int y) { ver[++tot] = y, Next[tot] = head[x], head[x] = tot; }
void tarjan(int x) {
	dfn[x] = low[x] = ++num;
	sta[++top] = x; ins[x] = 1;
	for(int i = head[x]; i; i = Next[i])
		if(!dfn[ver[i]]) tarjan(ver[i]), low[x] = min(low[x], low[ver[i]]);
		else if(ins[ver[i]]) low[x] = min(low[x], dfn[ver[i]]);
	if(dfn[x] == low[x]) {
		scc++; int z = 0;
		while(z != x) {
			z = sta[top--], ins[z] = 0, bel[z] = scc;
		}
	}
}
void clear() {
	rep(i, 1, n) head[i] = dfn[i] = low[i] = bel[i] = ins[i] = 0;
	top = num = scc = tot = 0;
}
int main() {
	int T; scanf("%d", &T);
	while(T--) {
		scanf("%d%d", &n, &m);
		rep(i, 1, m) {
			int x, y;
			scanf("%d%d", &x, &y);
			add(x, y);
		}
		rep(i, 1, n) if(!dfn[i]) tarjan(i);
		if(scc == 1) printf("No\n");
		else {
			printf("Yes\n");
			int cnt = 0;
			rep(i, 1, n) if(bel[i] == 1) cnt++;
			printf("%d %d\n", cnt, n - cnt);
			rep(i, 1, n) if(bel[i] == 1) printf("%d ", i);
			printf("\n");
			rep(i, 1, n) if(bel[i] != 1) printf("%d ", i);
			printf("\n");
		}
		clear();
	}
	return 0;
}


#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<set>
#include<stack>
#include<vector>
#include<queue>
#define LL long long
#define maxn 2000007
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
#define dwn(i,x,y) for(int i=(x);i>=(y);--i)
#define view(u,k) for(int k=fir[u];~k;k=nxt[k])
using namespace std;
int read()
{
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)&&ch!='-')ch=getchar();
    if(ch=='-')f=-1,ch=getchar();
    while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return x*f;
}
void write(int x)
{
    int f=0;char ch[20];
    if(x==0){putchar('0');putchar('\n');return ;}
    if(x<0){putchar('-'),x=-x;}
    while(x)ch[++f]=x%10+'0',x/=10;
    while(f)putchar(ch[f--]);putchar('\n');
}
int n,m,no,fir[maxn],nxt[maxn],v[maxn],cnte,dfn[maxn],low[maxn],ans[maxn],ins[maxn],stk[maxn],tp,tim,col[maxn],num;
void ade(int u1,int v1){v[cnte]=v1,nxt[cnte]=fir[u1],fir[u1]=cnte++;}
void tar(int u)
{
	dfn[u]=low[u]=++tim,ins[u]=1,stk[++tp]=u;
	view(u,k)
	{
		if(!dfn[v[k]])tar(v[k]),low[u]=min(low[u],low[v[k]]);
		else if(ins[v[k]])low[u]=min(low[u],dfn[v[k]]);
	}
	if(dfn[u]==low[u])
	{
		num++;int cnt=0;
		while(1)
		{
			cnt++;
			col[stk[tp]]=num,ins[stk[tp]]=0;
			if(stk[tp--]==u)break;
		}
		if(cnt==n)no=1;
	}
}
int gx(int x,int f){return x+f*n;}
int main()
{
	int t=read();
	while(t--)
	{
		//cout<<"start:"<<endl;
		n=read(),m=read(),no=0;int li=n<<1;
		rep(i,1,li)dfn[i]=0,fir[i]=-1;cnte=tim=num=0;
		rep(i,1,m)
		{
			int x=read(),y=read();
			if(x==y)continue;
			ade(gx(x,0),gx(y,0)),ade(gx(y,1),gx(x,1));
		}
		int c[2],co=1;c[0]=c[1]=0;
		rep(i,1,li)if(!dfn[i])tar(i);
		if(no){puts("No");continue;}
		rep(i,1,n)if(col[i]==1)co=0;
		rep(i,1,n)
		{
			if(col[gx(i,0)]==col[gx(i,1)]){puts("No");no=1;break;}
			if(col[gx(i,co)]==1)ans[i]=co,c[co]++;
			else ans[i]=co^1,c[co^1]++;
		}
		if(no)continue;
		puts("Yes");
		printf("%d %d\n",c[0],c[1]);
		rep(i,1,n)if(!ans[i])printf("%d ",i);puts("");
		rep(i,1,n)if(ans[i])printf("%d ",i);puts("");
	}
	return 0;
}
/*
4
3 4
1 1
2 2
3 3
1 3
3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3
1 1
1 1
2 4
1 1
1 2
2 1
2 2
*/


#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for (register int i = (a); i <= (b); ++i)
#define RREP(i, a, b) for (int i = (a); i >= (b); --i)
#define rep(i, a, b) for (register int i = (a); i < (b); ++i)
#define cl(x) memset(x, 0, sizeof(x))
#define rson m + 1, r, rt << 1 | 1
#define lson l, m, rt << 1
#define sqr(x) ((x) * (x))
#define cl(x) memset(x, 0, sizeof(x))

const int maxn = 1000000 + 500;
// const int maxn = 50;
const int maxm = 2000000 + 1000;
// const int maxm = 100;
const int maxt = 3000000 + 100;
const int maxk = 10 + 3;

typedef long long LL;
typedef long double LD;
typedef unsigned long long uLL;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;

const LL unit = 1LL;
const int INF = 0x3f3f3f3f;
const LL Inf = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-3;
const double inf = 1e15;
const double pi = acos(-1.0);
const LL mod = 1000000007LL;
// const LL mod = 1004535809LL, gg = 3LL, inv2 = 502267905LL;
// const LL mod = 167772161LL, gg = 3LL, inv2 = 83886081LL;
// const int mod = 998244353LL, gg = 3LL, inv2 = 499122177LL;

inline LL read()
{
	LL x = 0;
	bool t = false;
	char ch = getchar();
	while ((ch < '0' || ch > '9') && ch != '-')
		ch = getchar();
	if (ch == '-')
		t = true, ch = getchar();
	while (ch <= '9' && ch >= '0')
		x = x * 10 + ch - 48, ch = getchar();
	return t ? -x : x;
}

int n, m;
int u[maxn], v[maxn], deg[maxn];

struct Graph
{
	struct Edge
	{
		int to, next;
	};

	Edge edge[maxm];
	int n, tot, head[maxn];

	void init(int n)
	{
		tot = 1;
		this->n = n;
		for (int i = 0; i < n; ++i)
			head[i] = 0;
	}

	void AddEdge(int u, int v)
	{
		edge[tot] = (Edge){v, head[u]};
		head[u] = tot++;
	}
} G;

struct Scc
{
	int n, top, dfs_clock, scc_cnt;
	int dfn[maxn], low[maxn];
	int stack[maxn], ins[maxn], sccno[maxn];
	vector<int> scc[maxn];

	void init(int n)
	{
		top = dfs_clock = scc_cnt = 0;
		for (int i = 0; i < n; ++i)
			dfn[i] = 0, sccno[i] = 0, scc[i + 1].clear();
	}

	void Tarjan(Graph &G, int u)
	{
		dfn[u] = low[u] = ++dfs_clock;
		stack[++top] = u, ins[u] = 1;
		for (int i = G.head[u]; i; i = G.edge[i].next)
		{
			int v = G.edge[i].to;
			if (!dfn[v])
			{
				Tarjan(G, v);
				low[u] = min(low[u], low[v]);
			}
			else if (ins[v])
				low[u] = min(low[u], dfn[v]);
		}
		if (dfn[u] == low[u])
		{
			++scc_cnt;
			int v;
			do
			{
				v = stack[top--], ins[v] = 0;
				sccno[v] = scc_cnt, scc[scc_cnt].push_back(v);
			} while (u != v);
		}
	}

	void FindScc(Graph &G)
	{
		this->n = G.n;
		for (int i = 0; i < n; ++i)
			if (!dfn[i])
				Tarjan(G, i);
	}

	void show()
	{
		for (int i = 0; i < n; ++i)
			printf("sccno[%d]: %d\n", i, sccno[i]);
	}
} scc;

int main()
{
	// ios::sync_with_stdio(false);
	// cin.tie(0);
	// freopen("C:\\Users\\WA_TERMINATOR\\Desktop\\Helloworld\\input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int T;
	T = read();
	while (T--)
	{
		n = read(), m = read();
		G.init(n);
		scc.init(n);
		for (int i = 1; i <= n; ++i)
			deg[i] = 0;
		for (int i = 1; i <= m; ++i)
		{
			u[i] = read() - 1, v[i] = read() - 1;
			G.AddEdge(u[i], v[i]);
		}
		scc.FindScc(G);
		// scc.show();
		if (scc.scc_cnt == 1)
		{
			printf("No\n");
			continue;
		}
		for (int i = 1; i <= m; ++i)
			if (scc.sccno[u[i]] != scc.sccno[v[i]])
				++deg[scc.sccno[v[i]]];
		int id = 0;
		for (int i = 1; i <= scc.scc_cnt; ++i)
			if (!deg[i])
			{
				id = i;
				break;
			}
		printf("Yes\n");
		printf("%d %d\n", n - scc.scc[id].size(), scc.scc[id].size());
		for (int i = 1; i <= scc.scc_cnt; ++i)
			sort(scc.scc[i].begin(), scc.scc[i].end());
		for (int i = 1; i <= scc.scc_cnt; ++i)
		{
			if (i == id)
				continue;
			for (auto t : scc.scc[i])
				printf("%d ", t + 1);
		}
		printf("\n");
		for (auto t : scc.scc[id])
			printf("%d ", t + 1);
		printf("\n");
	}
	return 0;
}


/**
*
* Author: MARS
* Lang: GNU C++14
*
**/

#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >

typedef unsigned long long ull;
typedef long double ldbl;
typedef long long ll;
typedef double dbl;

const ldbl E = 2.71828182845904523536;
const ldbl pi = acos(-1);
const dbl eps = 1e-9;
const ll mod = 1e9+7;
const ll inf = 1LL<<30;

/** /////////// ** Code ** /////////// **/

const int N=1000010;
vector<int>adj[N],SCC_NUM[N];
int ticks = 1, current_scc =1;
int d[N],low[N];
bool stacked[N];

vector<int>v1,v2;
stack<int>s;
set<int> nd;
int deg[N];
int p[N];
ii a[N];

int Par(int i){ return p[i]=( i==p[i] )?i:Par(p[i]); }
bool same(int i,int j){ return Par(i)==Par(j); }

void mrg(int i,int j){
    if(same(i,j))return;
    i=Par(i);j=Par(j);
    if( rand()&1 )swap(i,j);
    p[i]=p[j];
}

void tarjan(int u)
{
    d[u] = low[u] = ticks++;
    s.push(u);
    stacked[u] = true;
    const vector<int> &out = adj[u];
    for(int k=0, m=out.size() ; k<m ; ++k)
    {
        const int &v = out[k];
        if (d[v] == -1)
        {
            tarjan(v);
            low[u] = min(low[u], low[v]);
        }
        else if (stacked[v])
            low[u] = min(low[u], low[v]);
    }
    if (d[u] == low[u])
    {
        int v;
        do
        {
            v = s.top();
            s.pop();
            stacked[v] = false;
            SCC_NUM[current_scc].push_back(v) ;
        }
        while (u != v);
        current_scc++;
    }
}

void _clear(int n){
    for(int i=1 ; i<=n ; i++){
        adj[i].clear();
        SCC_NUM[i].clear();
        d[i] = low[i] = -1;
        stacked[i] = 0;
        deg[i]=0;
    }

    ticks = 1, current_scc =1;
    while(s.size()) s.pop();
    nd.clear();
    v1.clear();
    v2.clear();
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        int n,m;
        scanf("%d%d",&n,&m);

        for(int i=0 ; i<m ; i++){
            scanf("%d%d",&a[i].F,&a[i].S);
            int u=a[i].F ,v=a[i].S;
            if(u != v)
                adj[u].push_back(v);
        }

        for(int i=1 ; i<=n ; i++){
            d[i] = low[i] = -1;
            p[i] = i;
        }

        for(int i=1 ; i<=n ; i++)
            if(d[i] == -1) tarjan(i);

        if(current_scc == 2){
            printf("No\n");
            _clear(n);
            continue;
        }

        for(int i = 1 ; i<current_scc ; i++){
            int lst = -1;
            for(auto u : SCC_NUM[i]){
                if(lst == -1){
                    lst=u;
                    continue;
                }
                mrg(lst, u);
                lst=u;
            }
        }

        for(int i=0 ; i<m ; i++){
            int u=a[i].F, v=a[i].S;
            if(same(u,v)) continue;
            u = Par(u);
            v = Par(v);
            nd.insert(u);
            nd.insert(v);
            deg[u]++;
        }

        int bst;
        for(auto u:nd)
            if(!deg[u])
                bst = u;

        for(int u=1 ; u<=n ; u++){
            if(Par(u) == bst) v1.push_back(u);
            else v2.push_back(u);
        }

        printf("Yes\n");
        printf("%d %d\n",v1.size(),v2.size());

        for(int i=0 ; i<v1.size() ; i++)
            printf("%d%c",v1[i]," \n"[i == v1.size()-1]);

        for(int i=0 ; i<v2.size() ; i++)
            printf("%d%c",v2[i]," \n"[i == v2.size()-1]);

        _clear(n);
    }
    return 0;
}


/**
*
* Author: MARS
* Lang: GNU C++14
*
**/

#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >

typedef unsigned long long ull;
typedef long double ldbl;
typedef long long ll;
typedef double dbl;

const ldbl E = 2.71828182845904523536;
const ldbl pi = acos(-1);
const dbl eps = 1e-9;
const ll mod = 1e9+7;
const ll inf = 1LL<<30;

/** /////////// ** Code ** /////////// **/

const int N=1000010;
vector<int>adj[N],SCC_NUM[N];
int ticks = 1, current_scc =1;
int d[N],low[N];
bool stacked[N];

vector<int>v1,v2;
stack<int>s;
set<int> nd;
int deg[N];
int p[N];
ii a[N];

int Par(int i){ return p[i]=( i==p[i] )?i:Par(p[i]); }
bool same(int i,int j){ return Par(i)==Par(j); }

void mrg(int i,int j){
    if(same(i,j))return;
    i=Par(i);j=Par(j);
    if( rand()&1 )swap(i,j);
    p[i]=p[j];
}

void tarjan(int u)
{
    d[u] = low[u] = ticks++;
    s.push(u);
    stacked[u] = true;
    const vector<int> &out = adj[u];
    for(int k=0, m=out.size() ; k<m ; ++k)
    {
        const int &v = out[k];
        if (d[v] == -1)
        {
            tarjan(v);
            low[u] = min(low[u], low[v]);
        }
        else if (stacked[v])
            low[u] = min(low[u], low[v]);
    }
    if (d[u] == low[u])
    {
        int v;
        do
        {
            v = s.top();
            s.pop();
            stacked[v] = false;
            SCC_NUM[current_scc].push_back(v) ;
        }
        while (u != v);
        current_scc++;
    }
}

void _clear(int n){
    for(int i=1 ; i<=n ; i++){
        adj[i].clear();
        SCC_NUM[i].clear();
        d[i] = low[i] = -1;
        stacked[i] = 0;
        deg[i]=0;
    }

    ticks = 1, current_scc =1;
    while(s.size()) s.pop();
    nd.clear();
    v1.clear();
    v2.clear();
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        int n,m;
        scanf("%d%d",&n,&m);

        for(int i=0 ; i<m ; i++){
            scanf("%d%d",&a[i].F,&a[i].S);
            int u=a[i].F ,v=a[i].S;
            if(u != v)
                adj[u].push_back(v);
        }

        for(int i=1 ; i<=n ; i++){
            d[i] = low[i] = -1;
            p[i] = i;
        }

        for(int i=1 ; i<=n ; i++)
            if(d[i] == -1) tarjan(i);

        if(current_scc == 2){
            printf("No\n");
            _clear(n);
            continue;
        }

        for(int i = 1 ; i<current_scc ; i++){
            int lst = -1;
            for(auto u : SCC_NUM[i]){
                if(lst == -1){
                    lst=u;
                    continue;
                }
                mrg(lst, u);
                lst=u;
            }
        }

        for(int i=0 ; i<m ; i++){
            int u=a[i].F, v=a[i].S;
            if(same(u,v)) continue;
            u = Par(u);
            v = Par(v);
            nd.insert(u);
            nd.insert(v);
            deg[u]++;
        }

        if(nd.size() == 0)
            nd.insert(Par(1));

        int bst;
        for(auto u:nd)
            if(!deg[u])
                bst = u;

        for(int u=1 ; u<=n ; u++){
            if(Par(u) == bst) v1.push_back(u);
            else v2.push_back(u);
        }

        printf("Yes\n");
        printf("%d %d\n",v1.size(),v2.size());

        for(int i=0 ; i<v1.size() ; i++)
            printf("%d%c",v1[i]," \n"[i == v1.size()-1]);

        for(int i=0 ; i<v2.size() ; i++)
            printf("%d%c",v2[i]," \n"[i == v2.size()-1]);

        _clear(n);
    }
    return 0;
}


/**
*
* Author: MARS
* Lang: GNU C++14
*
**/

#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >

typedef unsigned long long ull;
typedef long double ldbl;
typedef long long ll;
typedef double dbl;

const ldbl E = 2.71828182845904523536;
const ldbl pi = acos(-1);
const dbl eps = 1e-9;
const ll mod = 1e9+7;
const ll inf = 1LL<<30;

/** /////////// ** Code ** /////////// **/

const int N=1000010;
vector<int>adj[N],SCC_NUM[N];
int ticks = 1, current_scc =1;
int d[N],low[N];
bool stacked[N];

vector<int>v1,v2;
stack<int>s;
set<int> nd;
int deg[N];
int p[N];
ii a[N];

int Par(int i){ return p[i]=( i==p[i] )?i:Par(p[i]); }
bool same(int i,int j){ return Par(i)==Par(j); }

void mrg(int i,int j){
    if(same(i,j))return;
    i=Par(i);j=Par(j);
    if( rand()&1 )swap(i,j);
    p[i]=p[j];
}

void tarjan(int u)
{
    d[u] = low[u] = ticks++;
    s.push(u);
    stacked[u] = true;
    const vector<int> &out = adj[u];
    for(int k=0, m=out.size() ; k<m ; ++k)
    {
        const int &v = out[k];
        if (d[v] == -1)
        {
            tarjan(v);
            low[u] = min(low[u], low[v]);
        }
        else if (stacked[v])
            low[u] = min(low[u], low[v]);
    }
    if (d[u] == low[u])
    {
        int v;
        do
        {
            v = s.top();
            s.pop();
            stacked[v] = false;
            SCC_NUM[current_scc].push_back(v) ;
        }
        while (u != v);
        current_scc++;
    }
}

void _clear(int n){
    for(int i=1 ; i<=n ; i++){
        adj[i].clear();
        SCC_NUM[i].clear();
        d[i] = low[i] = -1;
        stacked[i] = 0;
        deg[i]=0;
    }

    ticks = 1, current_scc =1;
    while(s.size()) s.pop();
    nd.clear();
    v1.clear();
    v2.clear();
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        int n,m;
        scanf("%d%d",&n,&m);

        for(int i=0 ; i<m ; i++){
            scanf("%d%d",&a[i].F,&a[i].S);
            int u=a[i].F ,v=a[i].S;
            if(u != v)
                adj[u].push_back(v);
        }

        for(int i=1 ; i<=n ; i++){
            d[i] = low[i] = -1;
            p[i] = i;
        }

        for(int i=1 ; i<=n ; i++)
            if(d[i] == -1) tarjan(i);

        if(current_scc == 2){
            printf("No\n");
            _clear(n);
            continue;
        }

        for(int i = 1 ; i<current_scc ; i++){
            int lst = -1;
            for(auto u : SCC_NUM[i]){
                if(lst == -1){
                    lst=u;
                    continue;
                }
                mrg(lst, u);
                lst=u;
            }
        }

        for(int i=0 ; i<m ; i++){
            int u=a[i].F, v=a[i].S;
            if(same(u,v)) continue;
            u = Par(u);
            v = Par(v);
            nd.insert(u);
            nd.insert(v);
            deg[u]++;
        }

        if(nd.size() == 0)
            nd.insert(1);

        int bst;
        for(auto u:nd)
            if(!deg[u])
                bst = u;

        for(int u=1 ; u<=n ; u++){
            if(Par(u) == bst) v1.push_back(u);
            else v2.push_back(u);
        }

        printf("Yes\n");
        printf("%d %d\n",v1.size(),v2.size());

        for(int i=0 ; i<v1.size() ; i++)
            printf("%d%c",v1[i]," \n"[i == v1.size()-1]);

        for(int i=0 ; i<v2.size() ; i++)
            printf("%d%c",v2[i]," \n"[i == v2.size()-1]);

        _clear(n);
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

#define inf 0x3f3f3f3f
typedef long long LL;
#define cls(x) memset(x,0,sizeof(x))
#define For(i,j,k) for(register int i=(j);i<=(k);++i)
#define Rep(i,j,k) for(register int i=(j);i>=(k);--i)
#define rint register int
#define il inline

il int read(int x=0,int f=1,char ch='0')
{
    while(!isdigit(ch=getchar())) if(ch=='-') f=-1;
    while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return f*x;
}

const int N=1e6+5;
int head[N],ver[N],nxt[N],tot;
il void add(int x,int y) { ver[++tot]=y; nxt[tot]=head[x]; head[x]=tot; }
int n,m;

int dfn[N],low[N],num,col[N],ins[N],colnum;
stack<int> s;
vector<int> C[N]; int deg[N],ans[N];

void tar(int x)
{
    dfn[x]=low[x]=++num;
    s.push(x); ins[x]=1;
    for(rint i=head[x];i;i=nxt[i])
    {
        int y=ver[i];
        if(!dfn[y])
            tar(y),low[x]=min(low[x],low[y]);
        else if(ins[y])
            low[x]=min(low[x],dfn[y]);
    }
    if(dfn[x]==low[x])
    {
        ++colnum; int z;
        do{
            z=s.top(); s.pop(); ins[z]=0;
            col[z]=colnum; C[colnum].push_back(z);
        }while(x!=z);
    }
}

il void work()
{
    n=read(); m=read();
    For(i,1,m)
    {
        int x=read(),y=read(); if(x==y) continue;
        add(x,y);
    }
    For(i,1,n) if(!dfn[i]) tar(i);
    For(i,1,colnum) for(rint j=0;j<C[i].size();++j)
    {
        int x=C[i][j];
        for(rint k=head[x];k;k=nxt[k])
        {
            int y=ver[k];
           // printf("x %d y %d\n",x,y);
            if(col[y]==i) continue;
            ++deg[col[y]];
        }
    }
    if(colnum==1) return (void) (puts("No"));
    // For(i,1,n) printf("col[%d] %d deg %d\n",i,col[i],deg[col[i]]);
    puts("Yes");
    //printf("%d\n",colnum);
    int flag=0;
    For(i,1,colnum) if(!deg[i])
    {
        // printf("deg %d\n",deg[C[i][0]]);
        printf("%d %d\n",n-C[i].size(),C[i].size());
        For(j,1,n) if(col[j]!=i) printf("%d ",j); puts("");
        For(j,1,n) if(col[j]==i) printf("%d ",j); puts("");
        break;
    }
    For(i,1,n) head[i]=dfn[i]=deg[i]=0,C[i].clear();
    num=tot=colnum=0;

    // cls(head); cls(dfn); cls(deg);
    // For(i,1,n) C[i].clear(); num=colnum=tot=0;
}

int main()
{
    int T=read();
    while(T--) work();
    return 0;
}

/*
1
3 4
1 1
2 2
3 3
1 3

4
3 4
1 1
2 2
3 3
1 3

3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3

1 1
1 1

2 4
1 1
1 2
2 1
2 2

*/


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

#define inf 0x3f3f3f3f
typedef long long LL;
#define cls(x) memset(x,0,sizeof(x))
#define For(i,j,k) for(register int i=(j);i<=(k);++i)
#define Rep(i,j,k) for(register int i=(j);i>=(k);--i)
#define rint register int
#define il inline

il int read(int x=0,int f=1,char ch='0')
{
    while(!isdigit(ch=getchar())) if(ch=='-') f=-1;
    while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return f*x;
}

const int N=1e6+5;
int head[N],ver[N],nxt[N],tot;
il void add(int x,int y) { ver[++tot]=y; nxt[tot]=head[x]; head[x]=tot; }
int n,m;

int dfn[N],low[N],num,col[N],ins[N],colnum;
stack<int> s;
vector<int> C[N]; int deg[N],ans[N];

void tar(int x)
{
    dfn[x]=low[x]=++num;
    s.push(x); ins[x]=1;
    for(rint i=head[x];i;i=nxt[i])
    {
        int y=ver[i];
        if(!dfn[y])
            tar(y),low[x]=min(low[x],low[y]);
        else if(ins[y])
            low[x]=min(low[x],dfn[y]);
    }
    if(dfn[x]==low[x])
    {
        ++colnum; int z;
        do{
            z=s.top(); s.pop(); ins[z]=0;
            col[z]=colnum; C[colnum].push_back(z);
        }while(x!=z);
    }
}

il void work()
{
    cls(head); cls(dfn); cls(deg);
    For(i,1,n) C[i].clear(); num=colnum=tot=0;
    n=read(); m=read();
    For(i,1,m)
    {
        int x=read(),y=read(); if(x==y) continue;
        add(x,y);
    }
    For(i,1,n) if(!dfn[i]) tar(i);
    For(i,1,colnum) for(rint j=0;j<C[i].size();++j)
    {
        int x=col[C[i][j]];
        for(rint k=head[x];k;k=nxt[k])
        {
            int y=col[ver[k]]; if(y==i) continue;
            ++deg[y];
        }
    }
    if(colnum==1) return (void) (puts("No"));
    puts("Yes");
    //printf("%d\n",colnum);
    int flag=0;
    For(i,1,colnum) if(!deg[i])
    {
        printf("%d %d\n",n-C[i].size(),C[i].size());
        For(j,1,n) if(col[j]!=i) printf("%d ",j); puts("");
        For(j,1,n) if(col[j]==i) printf("%d ",j); puts("");
        return;
    }

}

int main()
{
    int T=read();
    while(T--) work();
    return 0;
}

/*
4
3 4
1 1
2 2
3 3
1 3

3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3

1 1
1 1

2 4
1 1
1 2
2 1
2 2

*/


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

#define inf 0x3f3f3f3f
typedef long long LL;
#define cls(x) memset(x,0,sizeof(x))
#define For(i,j,k) for(register int i=(j);i<=(k);++i)
#define Rep(i,j,k) for(register int i=(j);i>=(k);--i)
#define rint register int
#define il inline

il int read(int x=0,int f=1,char ch='0')
{
    while(!isdigit(ch=getchar())) if(ch=='-') f=-1;
    while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return f*x;
}

const int N=1e6+5;
int head[N],ver[N],nxt[N],tot;
il void add(int x,int y) { ver[++tot]=y; nxt[tot]=head[x]; head[x]=tot; }
int n,m;

int dfn[N],low[N],num,col[N],ins[N],colnum;
stack<int> s;
vector<int> C[N]; int deg[N],ans[N];

void tar(int x)
{
    dfn[x]=low[x]=++num;
    s.push(x); ins[x]=1;
    for(rint i=head[x];i;i=nxt[i])
    {
        int y=ver[i];
        if(!dfn[y])
            tar(y),low[x]=min(low[x],low[y]);
        else if(ins[y])
            low[x]=min(low[x],dfn[y]);
    }
    if(dfn[x]==low[x])
    {
        ++colnum; int z;
        do{
            z=s.top(); s.pop(); ins[z]=0;
            col[z]=colnum; C[colnum].push_back(z);
        }while(x!=z);
    }
}

il void work()
{
    cls(head); cls(dfn); cls(deg);
    For(i,1,n) C[i].clear(); num=colnum=tot=0;
    n=read(); m=read();
    For(i,1,m)
    {
        int x=read(),y=read(); if(x==y) continue;
        add(x,y);
    }
    For(i,1,n) if(!dfn[i]) tar(i);
    For(i,1,colnum) for(rint j=0;j<C[i].size();++j)
    {
        int x=C[i][j];
        for(rint k=head[x];k;k=nxt[k])
        {
            int y=ver[k];
           // printf("x %d y %d\n",x,y);
            if(col[y]==i) continue;
            ++deg[col[y]];
        }
    }
    if(colnum==1) return (void) (puts("No"));
    // For(i,1,n) printf("col[%d] %d deg %d\n",i,col[i],deg[col[i]]);
    puts("Yes");
    //printf("%d\n",colnum);
    int flag=0;
    For(i,1,colnum) if(!deg[i])
    {
        // printf("deg %d\n",deg[C[i][0]]);
        printf("%d %d\n",n-C[i].size(),C[i].size());
        For(j,1,n) if(col[j]!=i) printf("%d ",j); puts("");
        For(j,1,n) if(col[j]==i) printf("%d ",j); puts("");
        return;
    }

}

int main()
{
    int T=read();
    while(T--) work();
    return 0;
}

/*
1
3 4
1 1
2 2
3 3
1 3

4
3 4
1 1
2 2
3 3
1 3

3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3

1 1
1 1

2 4
1 1
1 2
2 1
2 2

*/


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

#define inf 0x3f3f3f3f
typedef long long LL;
#define cls(x) memset(x,0,sizeof(x))
#define For(i,j,k) for(register int i=(j);i<=(k);++i)
#define Rep(i,j,k) for(register int i=(j);i>=(k);--i)
#define rint register int
#define il inline

il int read(int x=0,int f=1,char ch='0')
{
    while(!isdigit(ch=getchar())) if(ch=='-') f=-1;
    while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return f*x;
}

const int N=1e6+5;
int head[N],ver[N],nxt[N],tot;
il void add(int x,int y) { ver[++tot]=y; nxt[tot]=head[x]; head[x]=tot; }
int n,m;

int dfn[N],low[N],num,col[N],ins[N],colnum;
stack<int> s;
vector<int> C[N]; int deg[N],ans[N];

void tar(int x)
{
    dfn[x]=low[x]=++num;
    s.push(x); ins[x]=1;
    for(rint i=head[x];i;i=nxt[i])
    {
        int y=ver[i];
        if(!dfn[y])
            tar(y),low[x]=min(low[x],low[y]);
        else if(ins[y])
            low[x]=min(low[x],dfn[y]);
    }
    if(dfn[x]==low[x])
    {
        ++colnum; int z;
        do{
            z=s.top(); s.pop(); ins[z]=0;
            col[z]=colnum; C[colnum].push_back(z);
        }while(x!=z);
    }
}

il void work()
{
    n=read(); m=read();
    For(i,1,m)
    {
        int x=read(),y=read(); if(x==y) continue;
        add(x,y);
    }
    For(i,1,n) if(!dfn[i]) tar(i);
    For(i,1,colnum) for(rint j=0;j<C[i].size();++j)
    {
        int x=C[i][j];
        for(rint k=head[x];k;k=nxt[k])
        {
            int y=ver[k];
           // printf("x %d y %d\n",x,y);
            if(col[y]==i) continue;
            ++deg[col[y]];
        }
    }
    if(colnum==1) return (void) (puts("No"));
    // For(i,1,n) printf("col[%d] %d deg %d\n",i,col[i],deg[col[i]]);
    puts("Yes");
    //printf("%d\n",colnum);
    int flag=0;
    For(i,1,colnum) if(!deg[i])
    {
        // printf("deg %d\n",deg[C[i][0]]);
        printf("%d %d\n",n-C[i].size(),C[i].size());
        For(j,1,n) if(col[j]!=i) printf("%d ",j); puts("");
        For(j,1,n) if(col[j]==i) printf("%d ",j); puts("");
        return;
    }
    // cls(head); cls(dfn); cls(deg);
    // For(i,1,n) C[i].clear(); num=colnum=tot=0;
}

il void _clear()
{
    For(i,1,n) head[i]=dfn[i]=deg[i]=0,C[i].clear();
    num=tot=colnum=0;
}

int main()
{
    int T=read();
    while(T--) work(),_clear();
    return 0;
}

/*
1
3 4
1 1
2 2
3 3
1 3

4
3 4
1 1
2 2
3 3
1 3

3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3

1 1
1 1

2 4
1 1
1 2
2 1
2 2

*/


#include <cmath>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int maxn = 1000000 + 10;
int n, m, cnt, vis[maxn];

std::vector<int> jud[maxn], joi[maxn];

inline void Deepfs_1(int x) {
  vis[x] = 1;
  for(int i = 0, size = jud[x].size(); i < size; ++i) if( vis[jud[x][i]] == 0 ) Deepfs_1(jud[x][i]);
}

inline void Deepfs_2(int x) {
  vis[x] = 1;
  for(int i = 0, size = joi[x].size(); i < size; ++i) if( vis[joi[x][i]] == 0 ) Deepfs_2(joi[x][i]);
}

inline int read() {
  register int ch = 0, x = 0;
  for( ; !isdigit(ch); ch = getchar()) ;
  for( ; isdigit(ch); x = (x * 10) + (ch ^ 48), ch = getchar()) ;
  return x;
}

int main(int argc, char const *argv[])
{
  scanf("%d", &n);
  while( ~scanf("%d%d", &n, &m) ) {
    for(int i = 1; i <= n; ++i) jud[i].clear(), joi[i].clear();
    for(int u = 0, v = 0, i = 1; i <= m; ++i) u = read(), v = read(), jud[u].push_back(v), joi[v].push_back(u);

    for(int i = 1; i <= n; ++i) vis[i] = 0;
    cnt = 0, Deepfs_1(1);
    for(int i = 1; i <= n; ++i) cnt = cnt + vis[i];
    if( cnt - n ) {
      printf("Yes\n"), printf("%d %d\n", cnt, n - cnt);
      for(int i = 1; i <= n; ++i) if( vis[i] == 1 ) printf("%d ", i); printf("\n");
      for(int i = 1; i <= n; ++i) if( vis[i] == 0 ) printf("%d ", i); printf("\n");
      continue;
    }

    for(int i = 1; i <= n; ++i) vis[i] = 0;
    cnt = 0, Deepfs_2(1);
    for(int i = 1; i <= n; ++i) cnt = cnt + vis[i];
    if( cnt - n ) {
      printf("Yes\n"), printf("%d %d\n", n - cnt, cnt);
      for(int i = 1; i <= n; ++i) if( vis[i] == 0 ) printf("%d ", i); printf("\n");
      for(int i = 1; i <= n; ++i) if( vis[i] == 1 ) printf("%d ", i); printf("\n");
      continue;
    }

    printf("No\n");
  }

  return 0;
}


#include <cmath>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int maxn = 1000000 + 10;
int n, m, cnt, vis[maxn];

std::vector<int> jud[maxn], joi[maxn];

inline void Deepfs_1(int x) {
  vis[x] = 1;
  for(int i = 0, size = jud[x].size(); i < size; ++i) if( vis[jud[x][i]] == 0 ) Deepfs_1(jud[x][i]);
}

inline void Deepfs_2(int x) {
  vis[x] = 1;
  for(int i = 0, size = joi[x].size(); i < size; ++i) if( vis[joi[x][i]] == 0 ) Deepfs_2(joi[x][i]);
}

int main(int argc, char const *argv[])
{
  scanf("%d", &n);
  while( ~scanf("%d%d", &n, &m) ) {
    for(int i = 1; i <= n; ++i) jud[i].clear(), joi[i].clear();
    for(int u = 0, v = 0, i = 1; i <= m; ++i) scanf("%d%d", &u, &v), jud[u].push_back(v), joi[v].push_back(u);

    memset(vis, 0, sizeof vis), cnt = 0, Deepfs_1(1);
    for(int i = 1; i <= n; ++i) cnt = cnt + vis[i];
    if( cnt - n ) {
      printf("Yes\n"), printf("%d %d\n", cnt, n - cnt);
      for(int i = 1; i <= n; ++i) if( vis[i] == 1 ) printf("%d ", i); printf("\n");
      for(int i = 1; i <= n; ++i) if( vis[i] == 0 ) printf("%d ", i); printf("\n");
      continue;
    }

    memset(vis, 0, sizeof vis), cnt = 0, Deepfs_2(1);
    for(int i = 1; i <= n; ++i) cnt = cnt + vis[i];
    if( cnt - n ) {
      printf("Yes\n"), printf("%d %d\n", cnt, n - cnt);
      for(int i = 1; i <= n; ++i) if( vis[i] == 0 ) printf("%d ", i); printf("\n");
      for(int i = 1; i <= n; ++i) if( vis[i] == 1 ) printf("%d ", i); printf("\n");
      continue;
    }

    printf("No\n");
  }

  return 0;
}


#include <cmath>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int maxn = 2000000 + 10;
int n, m, root, vis[maxn], size[maxn];

vector<int> rec[maxn];

int main(int argc, char const *argv[])
{
  scanf("%d", &n);
  while( ~scanf("%d%d", &n, &m) ) {
    for(int i = 1; i <= n; ++i) rec[i].clear(), vis[i] = 0, size[i] = 0;
    for(int u = 0, v = 0, i = 1; i <= m; ++i) scanf("%d%d", &u, &v), rec[u].push_back(v), ++size[u];
    for(int i = 1; i <= n; ++i) if( size[i] - n ) root = i;
    if( root ) {
      printf("Yes\n");
      printf("%d %d\n", size[root], n - size[root]);
      for(int i = 0; i < size[root]; vis[rec[root][i]] = 1, ++i) printf("%d ", rec[root][i]); printf("\n");
      for(int i = 1; i <= n; ++i) if( vis[i] == 0 ) printf("%d ", i); printf("\n");
      root = 0;
    }
    else printf("No\n");
  }

  return 0;
}


#include <cmath>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int maxn = 1000000 + 10;
int n, m, cnt, vis[maxn];

std::vector<int> jud[maxn], joi[maxn];

inline void Deepfs_1(int x) {
  vis[x] = 1;
  for(int i = 0, size = jud[x].size(); i < size; ++i) if( vis[jud[x][i]] == 0 ) Deepfs_1(jud[x][i]);
}

inline void Deepfs_2(int x) {
  vis[x] = 1;
  for(int i = 0, size = joi[x].size(); i < size; ++i) if( vis[joi[x][i]] == 0 ) Deepfs_2(joi[x][i]);
}

int main(int argc, char const *argv[])
{
  scanf("%d", &n);
  while( ~scanf("%d%d", &n, &m) ) {
    for(int i = 1; i <= n; ++i) jud[i].clear(), joi[i].clear();
    for(int u = 0, v = 0, i = 1; i <= m; ++i) scanf("%d%d", &u, &v), jud[u].push_back(v), joi[v].push_back(u);

    memset(vis, 0, sizeof vis), cnt = 0, Deepfs_1(1);
    for(int i = 1; i <= n; ++i) cnt = cnt + vis[i];
    if( cnt - n ) {
      printf("Yes\n"), printf("%d %d\n", cnt, n - cnt);
      for(int i = 1; i <= n; ++i) if( vis[i] == 1 ) printf("%d ", i); printf("\n");
      for(int i = 1; i <= n; ++i) if( vis[i] == 0 ) printf("%d ", i); printf("\n");
      continue;
    }

    memset(vis, 0, sizeof vis), cnt = 0, Deepfs_2(1);
    for(int i = 1; i <= n; ++i) cnt = cnt + vis[i];
    if( cnt - n ) {
      printf("Yes\n"), printf("%d %d\n", n - cnt, cnt);
      for(int i = 1; i <= n; ++i) if( vis[i] == 0 ) printf("%d ", i); printf("\n");
      for(int i = 1; i <= n; ++i) if( vis[i] == 1 ) printf("%d ", i); printf("\n");
      continue;
    }

    printf("No\n");
  }

  return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<stack>
#define maxn 1000010
#define sad printf("sad\n");
using namespace std;
int T,n,m,k,head[maxn],dfn[maxn],low[maxn],num,ans,a[maxn],size[maxn],du[maxn];
struct node
{
	int to,next;
}fafa[maxn*2];
struct date
{
	int u,v;
}e[maxn];
bool instack[maxn];
stack<int> s;
void adde(int u,int v)
{
	fafa[++k].next=head[u];
	fafa[k].to=v;head[u]=k;
}
void tarjan(int x)
{
	dfn[x]=low[x]=++num;s.push(x);instack[x]=true;
	for(int i=head[x];i;i=fafa[i].next)
	{
		int v=fafa[i].to;
		if(!dfn[v]) tarjan(v),low[x]=min(low[x],low[v]);
		else if(instack[v]) low[x]=min(low[x],low[v]);
	}
	if(dfn[x]==low[x])
	{
		ans++;
		while(s.top()!=x)
		{
			size[ans]++;
			a[s.top()]=ans;
			instack[s.top()]=false;
			s.pop();
		}
		size[ans]++;
		a[s.top()]=ans;
		instack[s.top()]=false;
		s.pop();
	}
}
void clear()
{
	for(int i=1;i<=n;i++) head[i]=dfn[i]=low[i]=head[i]=size[i]=du[i]=0;
	ans=num=k=0;
}
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		clear();
		scanf("%d%d",&n,&m);
		for(int i=1,u,v;i<=m;i++)
		{
			scanf("%d%d",&u,&v);
			e[i].u=u,e[i].v=v;
			if(u==v) continue;
			adde(v,u);
		}
		for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i);
		for(int i=1;i<=m;i++)
		{
			if(a[e[i].v]!=a[e[i].u]) du[a[e[i].u]]++;
		}
		int flag=0;
		if(ans>1)
		{
			for(int j=1;j<=ans;j++)
			{
				if(!du[j])
				{
					flag=1;
					puts("Yes");
					printf("%d %d \n",size[j],n-size[j]);
					for(int i=1;i<=n;i++) if(a[i]==j) printf("%d ",i);
					printf("\n");
					for(int i=1;i<=n;i++) if(a[i]!=j) printf("%d ",i);
					printf("\n");
					break;
				}
			}
		}
		if(!flag) puts("No");
	}
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<stack>
#define maxn 1000010
#define sad printf("sad\n");
using namespace std;
int T,n,m,k,head[maxn],dfn[maxn],low[maxn],num,ans,a[maxn],size[maxn],du[maxn];
struct node
{
	int to,next;
}fafa[maxn*2];
struct date
{
	int u,v;
}e[maxn];
bool instack[maxn];
stack<int> s;
void adde(int u,int v)
{
	fafa[++k].next=head[u];
	fafa[k].to=v;head[u]=k;
}
void tarjan(int x)
{
	dfn[x]=low[x]=++num;s.push(x);instack[x]=true;
	for(int i=head[x];i;i=fafa[i].next)
	{
		int v=fafa[i].to;
		if(!dfn[v]) tarjan(v),low[x]=min(low[x],low[v]);
		else if(instack[v]) low[x]=min(low[x],low[v]);
	}
	if(dfn[x]==low[x])
	{
		ans++;
		while(s.top()!=x)
		{
			size[ans]++;
			a[s.top()]=ans;
			instack[s.top()]=false;
			s.pop();
		}
		size[ans]++;
		a[s.top()]=ans;
		instack[s.top()]=false;
		s.pop();
	}
}
void clear()
{
	for(int i=1;i<=n;i++) head[i]=dfn[i]=low[i]=head[i]=size[i]=du[i]=0;
	ans=num=k=0;
}
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		clear();
		scanf("%d%d",&n,&m);
		for(int i=1,u,v;i<=m;i++)
		{
			scanf("%d%d",&u,&v);
			e[i].u=u,e[i].v=v;
			if(u==v) continue;
			adde(u,v);
		}
		for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i);
		for(int i=1;i<=m;i++)
		{
			if(a[e[i].v]!=a[e[i].u]) du[a[e[i].v]]++;
		}
		int flag=0;
		if(ans>1)
		{
			for(int j=1;j<=ans;j++)
			{
				if(!du[j])
				{
					flag=1;
					puts("Yes");
					printf("%d %d \n",size[j],n-size[j]);
					for(int i=1;i<=n;i++) if(a[i]==j) printf("%d ",i);
					printf("\n");
					for(int i=1;i<=n;i++) if(a[i]!=j) printf("%d ",i);
					printf("\n");
					break;
				}
			}
		}
		if(!flag) puts("No");
	}
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<stack>
#define maxn 1000010
#define sad printf("sad\n");
using namespace std;
int T,n,m,k,head[maxn],dfn[maxn],low[maxn],num,ans,a[maxn],size[maxn],du[maxn];
struct node
{
	int to,next;
}fafa[maxn*2];
struct date
{
	int u,v;
}e[maxn];
bool instack[maxn];
stack<int> s;
void adde(int u,int v)
{
	fafa[++k].next=head[u];
	fafa[k].to=v;head[u]=k;
}
void tarjan(int x)
{
	dfn[x]=low[x]=++num;s.push(x);instack[x]=true;
	for(int i=head[x];i;i=fafa[i].next)
	{
		int v=fafa[i].to;
		if(!dfn[v]) tarjan(v),low[x]=min(low[x],low[v]);
		else if(instack[v]) low[x]=min(low[x],low[v]);
	}
	if(dfn[x]==low[x])
	{
		ans++;
		while(s.top()!=x)
		{
			size[ans]++;
			a[s.top()]=ans;
			instack[s.top()]=false;
			s.pop();
		}
		size[ans]++;
		a[s.top()]=ans;
		instack[s.top()]=false;
		s.pop();
	}
}
void clear()
{
	memset(dfn,0,sizeof(dfn));
	memset(low,0,sizeof(low));
	memset(size,0,sizeof(size));
	memset(a,0,sizeof(a));
	memset(head,0,sizeof(head));
	k=0;ans=0;
}
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		clear();
		scanf("%d%d",&n,&m);
		for(int i=1,u,v;i<=m;i++)
		{
			scanf("%d%d",&u,&v);
			e[i].u=u,e[i].v=v;
			if(u==v) continue;
			adde(v,u);
		}
		for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i);
		for(int i=1;i<=m;i++)
		{
			if(a[e[i].v]!=a[e[i].u]) du[a[e[i].u]]++;
		}
		int flag=0;
		if(ans>1)
		{
			for(int j=1;j<=ans;j++)
			{
				if(!du[j])
				{
					flag=1;
					puts("Yes");
					printf("%d %d \n",size[j],n-size[j]);
					for(int i=1;i<=n;i++) if(a[i]==j) printf("%d ",i);
					printf("\n");
					for(int i=1;i<=n;i++) if(a[i]!=j) printf("%d ",i);
					printf("\n");
					break;
				}
			}
		}
		if(!flag) puts("No");
	}
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<stack>
#define maxn 100010
#define sad printf("sad\n");
using namespace std;
int T,n,m,k,head[maxn],dfn[maxn],low[maxn],num,ans,a[maxn],size[maxn];
struct node
{
	int to,next;
}fafa[maxn*2];
bool instack[maxn];
stack<int> s;
void adde(int u,int v)
{
	fafa[++k].next=head[u];
	fafa[k].to=v;head[u]=k;
}
void tarjan(int x)
{
	dfn[x]=low[x]=++num;
	s.push(x);instack[x]=true;
	for(int i=head[x];i;i=fafa[i].next)
	{
		int v=fafa[i].to;
		if(!dfn[v]) tarjan(v),low[x]=min(low[x],low[v]);
		else low[x]=min(low[x],low[v]);
	}
	if(dfn[x]==low[x])
	{
		ans++;
		while(s.top()!=x)
		{
			size[ans]++;
			a[s.top()]=ans;
			instack[s.top()]=false;
			s.pop();
		}
		size[ans]++;
		a[s.top()]=ans;
		instack[s.top()]=false;
		s.pop();
	}
}
void clear()
{
	memset(dfn,0,sizeof(dfn));
	memset(low,0,sizeof(low));
	memset(size,0,sizeof(size));
	memset(a,0,sizeof(a));
	memset(head,0,sizeof(head));
	k=0;ans=0;
}
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		clear();
		scanf("%d%d",&n,&m);
		for(int i=1,u,v;i<=m;i++)
		{
			scanf("%d%d",&u,&v);
			if(u==v) continue;
			adde(u,v);
		}
		for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i);
		if(ans>1)
		{
			puts("Yes");
			printf("%d %d \n",size[1],n-size[1]);
			for(int i=1;i<=n;i++) if(a[i]==1) printf("%d ",i);
			printf("\n");
			for(int i=1;i<=n;i++) if(a[i]!=1) printf("%d ",i);
			printf("\n");
		}
		else puts("No");
	}
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<stack>
#define maxn 100010
#define sad printf("sad\n");
using namespace std;
int T,n,m,k,head[maxn],dfn[maxn],low[maxn],num,ans,a[maxn],size[maxn];
struct node
{
	int to,next;
}fafa[maxn*2];
bool instack[maxn];
stack<int> s;
void adde(int u,int v)
{
	fafa[++k].next=head[u];
	fafa[k].to=v;head[u]=k;
}
void tarjan(int x)
{
	dfn[x]=low[x]=++num;s.push(x);instack[x]=true;
	for(int i=head[x];i;i=fafa[i].next)
	{
		int v=fafa[i].to;
		if(!dfn[v]) tarjan(v),low[x]=min(low[x],low[v]);
		else if(instack[v]) low[x]=min(low[x],low[v]);
	}
	if(dfn[x]==low[x])
	{
		ans++;
		while(s.top()!=x)
		{
			size[ans]++;
			a[s.top()]=ans;
			instack[s.top()]=false;
			s.pop();
		}
		size[ans]++;
		a[s.top()]=ans;
		instack[s.top()]=false;
		s.pop();
	}
}
void clear()
{
	memset(dfn,0,sizeof(dfn));
	memset(low,0,sizeof(low));
	memset(size,0,sizeof(size));
	memset(a,0,sizeof(a));
	memset(head,0,sizeof(head));
	k=0;ans=0;
}
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		clear();
		scanf("%d%d",&n,&m);
		for(int i=1,u,v;i<=m;i++)
		{
			scanf("%d%d",&u,&v);
			if(u==v) continue;
			adde(u,v);
		}
		for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i);
		if(ans>1)
		{
			puts("Yes");
			printf("%d %d \n",size[1],n-size[1]);
			for(int i=1;i<=n;i++) if(a[i]==1) printf("%d ",i);
			printf("\n");
			for(int i=1;i<=n;i++) if(a[i]!=1) printf("%d ",i);
			printf("\n");
		}
		else puts("No");
	}
}


#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
#define pb push_back
#define mk make_pair
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repp(a,b,c) for(int a=b;a<=c;a++)
#define mem(a,b) memset(a,b,sizeof(a))
const int inf=0x3f3f3f3f;
const int maxn=1e6+10;
int color[maxn];
vector<int>vis[maxn];
vector<int>vis1[maxn];
void useiostream()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int cnt;
bool dfs(int num)
{
	color[num]=1;cnt++;
	for(int i=0;i<vis[num].size();i++)
	{
		int v=vis[num][i];
		if(color[v])continue;
		dfs(v);
	}
}
bool dfs1(int num)
{
	color[num]=1;cnt++;
	for(int i=0;i<vis1[num].size();i++)
	{
		int v=vis[num][i];
		if(color[v])continue;
		dfs(v);
	}
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int n,m;
		cin>>n>>m;
		for(int i=1;i<=n;i++)
		{
			color[i]=0;
			vis[i].clear();
			vis1[i].clear();
		}
		repp(i,1,m)
		{
			int a,b;
			cin>>a>>b;
			if(a==b)continue;
			vis[a].pb(b);
			vis1[b].pb(a);
		}
		cnt=0;
		dfs(1);
		if(cnt==n)
		{
			for(int i=1;i<=n;i++)color[i]=0;
			cnt=0;
			dfs1(1);
			if(cnt==n)
			{
				cout<<"No"<<endl;
			}
			else
			{
				cout<<"Yes"<<endl;
				cout<<n-cnt<<" "<<cnt<<endl;
				repp(i,1,n)
					if(!color[i])cout<<i<<" ";
				cout<<endl;
				repp(i,1,n)
				{
					if(color[i])cout<<i<<" ";
				}
				cout<<endl;
			}
		}
		else
		{
			cout<<"Yes"<<endl;
			cout<<cnt<<" "<<n-cnt<<endl;
			repp(i,1,n)
				if(color[i])cout<<i<<" ";
			cout<<endl;
			repp(i,1,n)
			{
				if(!color[i])cout<<i<<" ";
			}
			cout<<endl;
		}
	}
}

/*

4
3 4
1 1
2 2
3 3
1 3

3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3

1 1
1 1

2 4
1 1
1 2
2 1
2 2

*/


#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
#define pb push_back
#define mk make_pair
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repp(a,b,c) for(int a=b;a<=c;a++)
#define mem(a,b) memset(a,b,sizeof(a))
const int inf=0x3f3f3f3f;
const int maxn=1e6+10;
int color[maxn];
vector<int>vis[maxn];
vector<int>vis1[maxn];
void useiostream()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int cnt;
void dfs(int num)
{
	color[num]=1;cnt++;
	for(int i=0;i<vis[num].size();i++)
	{
		int v=vis[num][i];
		if(color[v])continue;
		dfs(v);
	}
}
void dfs1(int num)
{
	color[num]=1;cnt++;
	for(int i=0;i<vis1[num].size();i++)
	{
		int v=vis[num][i];
		if(color[v])continue;
		dfs1(v);
	}
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int n,m;
		cin>>n>>m;
		for(int i=1;i<=n;i++)
		{
			color[i]=0;
			vis[i].clear();
			vis1[i].clear();
		}
		repp(i,1,m)
		{
			int a,b;
			cin>>a>>b;
			if(a==b)continue;
			vis[a].pb(b);
			vis1[b].pb(a);
		}
		cnt=0;
		dfs(1);
		if(cnt==n)
		{
			for(int i=1;i<=n;i++)color[i]=0;
			cnt=0;
			dfs1(1);
			if(cnt==n)
			{
				cout<<"No"<<endl;
			}
			else
			{
				cout<<"Yes"<<endl;
				cout<<n-cnt<<" "<<cnt<<endl;
				repp(i,1,n)
					if(!color[i])cout<<i<<" ";
				cout<<endl;
				repp(i,1,n)
				{
					if(color[i])cout<<i<<" ";
				}
				cout<<endl;
			}
		}
		else
		{
			cout<<"Yes"<<endl;
			cout<<cnt<<" "<<n-cnt<<endl;
			repp(i,1,n)
				if(color[i])cout<<i<<" ";
			cout<<endl;
			repp(i,1,n)
			{
				if(!color[i])cout<<i<<" ";
			}
			cout<<endl;
		}
	}
}

/*

4
3 4
1 1
2 2
3 3
1 3

3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3

1 1
1 1

2 4
1 1
1 2
2 1
2 2

*/


#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
#define pb push_back
#define mk make_pair
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repp(a,b,c) for(int a=b;a<=c;a++)
#define mem(a,b) memset(a,b,sizeof(a))
const int inf=0x3f3f3f3f;
const int maxn=1e6+10;
int color[maxn];
vector<int>vis[maxn];
vector<int>vis1[maxn];
void useiostream()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int cnt;
void dfs(int num)
{
	color[num]=1;cnt++;
	for(int i=0;i<vis[num].size();i++)
	{
		int v=vis[num][i];
		if(color[v])continue;
		dfs(v);
	}
}
void dfs1(int num)
{
	color[num]=1;cnt++;
	for(int i=0;i<vis1[num].size();i++)
	{
		int v=vis1[num][i];
		if(color[v])continue;
		dfs1(v);
	}
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int n,m;
		cin>>n>>m;
		for(int i=1;i<=n;i++)
		{
			color[i]=0;
			vis[i].clear();
			vis1[i].clear();
		}
		repp(i,1,m)
		{
			int a,b;
			cin>>a>>b;
			if(a==b)continue;
			vis[a].pb(b);
			vis1[b].pb(a);
		}
		cnt=0;
		dfs(1);
		if(cnt==n)
		{
			for(int i=1;i<=n;i++)color[i]=0;
			cnt=0;
			dfs1(1);
			if(cnt==n)
			{
				cout<<"No"<<endl;
			}
			else
			{
				cout<<"Yes"<<endl;
				cout<<n-cnt<<" "<<cnt<<endl;
				repp(i,1,n)
					if(!color[i])cout<<i<<" ";
				cout<<endl;
				repp(i,1,n)
				{
					if(color[i])cout<<i<<" ";
				}
				cout<<endl;
			}
		}
		else
		{
			cout<<"Yes"<<endl;
			cout<<cnt<<" "<<n-cnt<<endl;
			repp(i,1,n)
				if(color[i])cout<<i<<" ";
			cout<<endl;
			repp(i,1,n)
			{
				if(!color[i])cout<<i<<" ";
			}
			cout<<endl;
		}
	}
}

/*

4
3 4
1 1
2 2
3 3
1 3

3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3

1 1
1 1

2 4
1 1
1 2
2 1
2 2

*/


#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
#define pb push_back
#define mk make_pair
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repp(a,b,c) for(int a=b;a<=c;a++)
#define mem(a,b) memset(a,b,sizeof(a))
#define endl '\n'
const int inf=0x3f3f3f3f;
const int maxn=1e6+10;
int color[maxn];
vector<int>vis[maxn];
vector<int>vis1[maxn];
void useiostream()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int cnt;
void dfs(int num)
{
	color[num]=1;cnt++;
	for(int i=0;i<vis[num].size();i++)
	{
		int v=vis[num][i];
		if(color[v])continue;
		dfs(v);
	}
}
void dfs1(int num)
{
	color[num]=1;cnt++;
	for(int i=0;i<vis1[num].size();i++)
	{
		int v=vis1[num][i];
		if(color[v])continue;
		dfs1(v);
	}
}
int main()
{
	useiostream();
	int T;
	cin>>T;
	while(T--)
	{
		int n,m;
		cin>>n>>m;
		for(int i=1;i<=n;i++)
		{
			color[i]=0;
			vis[i].clear();
			vis1[i].clear();
		}
		repp(i,1,m)
		{
			int a,b;
			cin>>a>>b;
			if(a==b)continue;
			vis[a].pb(b);
			vis1[b].pb(a);
		}
		cnt=0;
		dfs(1);
		if(cnt==n)
		{
			for(int i=1;i<=n;i++)color[i]=0;
			cnt=0;
			dfs1(1);
			if(cnt==n)
			{
				cout<<"No"<<endl;
			}
			else
			{
				cout<<"Yes"<<endl;
				cout<<n-cnt<<" "<<cnt<<endl;
				repp(i,1,n)
					if(!color[i])cout<<i<<" ";
				cout<<endl;
				repp(i,1,n)
				{
					if(color[i])cout<<i<<" ";
				}
				cout<<endl;
			}
		}
		else
		{
			cout<<"Yes"<<endl;
			cout<<cnt<<" "<<n-cnt<<endl;
			repp(i,1,n)
				if(color[i])cout<<i<<" ";
			cout<<endl;
			repp(i,1,n)
			{
				if(!color[i])cout<<i<<" ";
			}
			cout<<endl;
		}
	}
}

/*

4
3 4
1 1
2 2
3 3
1 3

3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3

1 1
1 1

2 4
1 1
1 2
2 1
2 2

*/


#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
#define pb push_back
#define mk make_pair
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repp(a,b,c) for(int a=b;a<=c;a++)
#define mem(a,b) memset(a,b,sizeof(a))
const int inf=0x3f3f3f3f;
const int maxn=1e6+10;
int color[maxn];
vector<int>vis[maxn];
vector<int>vis1[maxn];
void useiostream()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int cnt;
void dfs(int num)
{
	color[num]=1;cnt++;
	for(int i=0;i<vis[num].size();i++)
	{
		int v=vis[num][i];
		if(color[v])continue;
		dfs(v);
	}
}
void dfs1(int num)
{
	color[num]=1;cnt++;
	for(int i=0;i<vis1[num].size();i++)
	{
		int v=vis[num][i];
		if(color[v])continue;
		dfs(v);
	}
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int n,m;
		cin>>n>>m;
		for(int i=1;i<=n;i++)
		{
			color[i]=0;
			vis[i].clear();
			vis1[i].clear();
		}
		repp(i,1,m)
		{
			int a,b;
			cin>>a>>b;
			if(a==b)continue;
			vis[a].pb(b);
			vis1[b].pb(a);
		}
		cnt=0;
		dfs(1);
		if(cnt==n)
		{
			for(int i=1;i<=n;i++)color[i]=0;
			cnt=0;
			dfs1(1);
			if(cnt==n)
			{
				cout<<"No"<<endl;
			}
			else
			{
				cout<<"Yes"<<endl;
				cout<<n-cnt<<" "<<cnt<<endl;
				repp(i,1,n)
					if(!color[i])cout<<i<<" ";
				cout<<endl;
				repp(i,1,n)
				{
					if(color[i])cout<<i<<" ";
				}
				cout<<endl;
			}
		}
		else
		{
			cout<<"Yes"<<endl;
			cout<<cnt<<" "<<n-cnt<<endl;
			repp(i,1,n)
				if(color[i])cout<<i<<" ";
			cout<<endl;
			repp(i,1,n)
			{
				if(!color[i])cout<<i<<" ";
			}
			cout<<endl;
		}
	}
}

/*

4
3 4
1 1
2 2
3 3
1 3

3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3

1 1
1 1

2 4
1 1
1 2
2 1
2 2

*/


#include<bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>
#define ll long long
#define pb push_back
using namespace std;
int n,m;
const int maxn=1e6+10;
vector<int> a[maxn],b[maxn];
int f=0;
int va[maxn],vb[maxn];

void dfs(int x)
{
	for(int i:a[x])
	{
		if(vb[i]!=-1) continue;
		vb[i]=0;
		va[i]=1;
		dfs(i);
	}
}
void dfs2(int x)
{
	for(int i:b[x])
	{
		if(va[i]!=-1) continue;
		va[i]=0;
		vb[i]=1;
		dfs2(i);
	}
}

bool ok1()
{
	int c=0;
	for(int i=1;i<=n;i++) if(va[i]==1) c++;
	if(c==n) return 0;
	printf("Yes\n");
	printf("%d %d\n",c,n-c);
	for(int i=1;i<=n;i++)
	{
		if(va[i]==1) printf("%d ",i);
	}
	printf("\n");
	for(int i=1;i<=n;i++)
	{
		if(va[i]==1) continue;
		printf("%d ",i);
	}
	printf("\n");
	return 1;
}

bool ok2()
{
	int c=0;
	for(int i=1;i<=n;i++) if(vb[i]==1) c++;
	if(c==n) return 0;
	printf("Yes\n");
	printf("%d %d\n",n-c,c);
	for(int i=1;i<=n;i++)
	{
		if(vb[i]!=1) printf("%d ",i);
	}
	printf("\n");
	for(int i=1;i<=n;i++)
	{
		if(vb[i]==1)
		printf("%d ",i);
	}
	printf("\n");
	return 1;
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		f=0;
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++) a[i].clear(),b[i].clear();
		for(int i=1,x,y;i<=m;i++)
		{
			scanf("%d%d",&x,&y);
			a[x].pb(y),b[y].pb(x);
		}
		for(int i=1;i<=n;i++) va[i]=vb[i]=-1;
		va[1]=1,vb[1]=0;
		dfs(1);
		if(ok1()) continue;
		for(int i=1;i<=n;i++) va[i]=vb[i]=-1;
		va[1]=0,vb[1]=1;
		dfs2(1);
		if(ok2()) continue;
		printf("No\n");
	}
	return 0;
}
/*
4

3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3

1 1
1 1

2 4
1 1
1 2
2 1
2 2

*/


#include<bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>
#define ll long long
#define pb push_back
using namespace std;
int n,m;
const int maxn=1e6+10;
vector<int> a[maxn],b[maxn];
int f=0;
int va[maxn],vb[maxn];

void dfs(int x)
{
	for(int i:a[x])
	{
		if(vb[i]!=-1) continue;
		vb[i]=0;
		va[i]=1;
		dfs(i);
	}
}
void dfs2(int x)
{
	for(int i:b[x])
	{
		if(va[i]!=-1) continue;
		va[i]=0;
		vb[i]=1;
		dfs(i);
	}
}

bool ok1()
{
	int c=0;
	for(int i=1;i<=n;i++) if(va[i]==1) c++;
	if(c==n) return 0;
	printf("Yes\n");
	printf("%d %d\n",c,n-c);
	for(int i=1;i<=n;i++)
	{
		if(va[i]==1) printf("%d ",i);
	}
	printf("\n");
	for(int i=1;i<=n;i++)
	{
		if(va[i]==1) continue;
		printf("%d ",i);
	}
	printf("\n");
	return 1;
}

bool ok2()
{
	int c=0;
	for(int i=1;i<=n;i++) if(vb[i]==1) c++;
	if(c==n) return 0;
	printf("Yes\n");
	printf("%d %d\n",n-c,c);
	for(int i=1;i<=n;i++)
	{
		if(vb[i]!=1) printf("%d ",i);
	}
	printf("\n");
	for(int i=1;i<=n;i++)
	{
		if(vb[i]==1)
		printf("%d ",i);
	}
	printf("\n");
	return 1;
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		f=0;
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++) a[i].clear(),b[i].clear();
		for(int i=1,x,y;i<=m;i++)
		{
			scanf("%d%d",&x,&y);
			a[x].pb(y),b[y].pb(x);
		}
		for(int i=1;i<=n;i++) va[i]=vb[i]=-1;
		va[1]=1,vb[1]=0;
		dfs(1);
		if(ok1()) continue;
		for(int i=1;i<=n;i++) va[i]=vb[i]=-1;
		va[1]=0,vb[1]=1;
		dfs2(1);
		if(ok2()) continue;
		printf("No\n");
	}
	return 0;
}
/*
4

3 7
1 1
1 2
1 3
2 2
3 1
3 2
3 3

1 1
1 1

2 4
1 1
1 2
2 1
2 2

*/


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
#define rg register
void read(int &x){
    char ch;bool ok;
    for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
    for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
    if(ok)x=-x;
}
const int maxn=2e6+10;
int T,n,m,cnt,now,pre[maxn*2],nxt[maxn*2],h[maxn];
bool vis[maxn];
void add(int x,int y){
    pre[++cnt]=y,nxt[cnt]=h[x],h[x]=cnt;
    pre[++cnt]=x,nxt[cnt]=h[y],h[y]=cnt;
}
void dfs1(int x){
    vis[x]=1;now++;
    for(rg int i=h[x];i;i=nxt[i])
	if(!vis[pre[i]-n])dfs1(pre[i]-n);
}
void dfs2(int x){
    vis[x]=1;now++;
    for(rg int i=h[x];i;i=nxt[i])
	if(!vis[pre[i]+n])dfs2(pre[i]+n);
}
int main(){
    read(T);
    while(T--){
	read(n),read(m);memset(vis,0,sizeof vis),memset(h,0,sizeof h),cnt=0;
	for(rg int i=1,x,y;i<=m;i++)read(x),read(y),add(x,y+n);
	now=0;dfs1(1);
	if(now==n){
	    now=0;dfs2(n+1);
	    if(now==n){printf("No\n");continue;}
	    printf("Yes\n");
	    printf("%d %d\n",n-now,now);
	    for(rg int i=n+1;i<=n*2;i++)if(!vis[i])printf("%d ",i-n);printf("\n");
	    for(rg int i=n+1;i<=n*2;i++)if(vis[i])printf("%d ",i-n);printf("\n");
	}
	else {
	    printf("Yes\n");
	    printf("%d %d\n",now,n-now);
	    for(rg int i=1;i<=n;i++)if(vis[i])printf("%d ",i);printf("\n");
	    for(rg int i=1;i<=n;i++)if(!vis[i])printf("%d ",i);printf("\n");
	}
    }
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
#define rg register
void read(int &x){
    char ch;bool ok;
    for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
    for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
    if(ok)x=-x;
}
const int maxn=2e6+10;
int T,n,m,cnt,now,pre[maxn*2],nxt[maxn*2],h[maxn];
bool vis[maxn];
void add(int x,int y){
    pre[++cnt]=y,nxt[cnt]=h[x],h[x]=cnt;
    pre[++cnt]=x,nxt[cnt]=h[y],h[y]=cnt;
}
void dfs1(int x){
    vis[x]=1;now++;
    for(rg int i=h[x];i;i=nxt[i])
	if(!vis[pre[i]-n])dfs1(pre[i]-n);
}
void dfs2(int x){
    vis[x]=1;now++;
    for(rg int i=h[x];i;i=nxt[i])
	if(!vis[pre[i]+n])dfs2(pre[i]+n);
}
int main(){
    read(T);
    while(T--){
	read(n),read(m);
	for(rg int i=1;i<=n*2;i++)h[i]=vis[i]=0;cnt=0;
	for(rg int i=1,x,y;i<=m;i++)read(x),read(y),add(x,y+n);
	now=0;dfs1(1);
	if(now==n){
	    now=0;dfs2(n+1);
	    if(now==n){printf("No\n");continue;}
	    printf("Yes\n");
	    printf("%d %d\n",n-now,now);
	    for(rg int i=n+1;i<=n*2;i++)if(!vis[i])printf("%d ",i-n);printf("\n");
	    for(rg int i=n+1;i<=n*2;i++)if(vis[i])printf("%d ",i-n);printf("\n");
	}
	else {
	    printf("Yes\n");
	    printf("%d %d\n",now,n-now);
	    for(rg int i=1;i<=n;i++)if(vis[i])printf("%d ",i);printf("\n");
	    for(rg int i=1;i<=n;i++)if(!vis[i])printf("%d ",i);printf("\n");
	}
    }
}


#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define test cerr << '!' << endl;
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main0 ();
int main () {
	#ifndef ONLINE_JUDGE
		freopen("C:\\Users\\98497\\Desktop\\code\\file.in", "r", stdin);
	#endif
	ios::sync_with_stdio(false);
	// clock_t start,end;
	// start = clock();
	main0();
	// end = clock();
	// cout << (end - start) << endl;
	#ifndef ONLINE_JUDGE
		fclose(stdin);
	#endif
	return 0;
}

const int INF = 0x3f3f3f3f;
const int N = 1e6 + 5;
const int M = 1e5;
const int mod = 1e9 + 7;

vector <int> e[N];
int dfn[N], low[N];
int col[N], vis[N], cnt[N], deg[N];
int n, m;
int flag, deep;

stack <int> stk;
void tarjan (int u) {
	dfn[u] = low[u] = ++deep;
	vis[u] = 1;
	stk.push(u);
	for (int i = 0;i < e[u].size();i++) {
		int v = e[u][i];
		if (!dfn[v]) {
			tarjan(v);
			low[u] = min(low[u], low[v]);
		} else {
			 if (vis[v])
				 low[u] = min(low[u], low[v]);
		}
	}

	if (dfn[u] == low[u]) {
		col[0]++;
		while (true) {
			int t = stk.top(); stk.pop();
			col[t] = col[0];
			vis[t] = 0;
			if (t == u) break;
		}
	}
}

int main0 () {
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d", &n, &m);
		if (n == 1) {
			scanf("%d%d", &n, &m);
			printf("NO\n");
			continue;
		}

		deep = 0;
		flag = 0;
		//col[0] = 0;
		for (int i = 0;i <= n;i++) {
			e[i].clear();
			dfn[i] = 0;
			low[i] = 0;
			vis[i] = 0;
			col[i] = 0;
			cnt[i] = deg[i] = 0;
		}
		for (int i = 1;i <= m;i++) {
			int u, v;
			scanf("%d%d", &u, &v);
			if (u == v) continue;
			e[u].pb(v);
		}

		for (int i = 1;i <= n;i++) {
			if (!dfn[i]) tarjan(i);
		}

		for (int i = 1;i <= n;i++) {
			//cout << i << ':' << col[i] << endl;
			cnt[col[i]]++;
		}

		for (int i = 1;i <= n;i++) {
			for (int j = 0;j < e[i].size();j++) {
				int v = e[i][j];
				if (col[i] != col[v]) deg[col[i]]++;
			}
			if ((!deg[col[i]]) && (cnt[col[i]] < n)) {
				flag = col[i];
				break;
			}
		}

		if (flag) {
			printf("YES\n");
			printf("%d %d\n", cnt[flag], n - cnt[flag]);
			for (int i = 1;i <= n;i++) {
				if (col[i] == flag) printf("%d ", i);
			} puts("");
			for (int i = 1;i <= n;i++) {
				if (col[i] != flag) printf("%d ", i);
			} puts("");
		} else {
			printf("NO\n");
		}
	}
}


#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define test cerr << '!' << endl;
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main0 ();
int main () {
	#ifndef ONLINE_JUDGE
		freopen("C:\\Users\\98497\\Desktop\\code\\file.in", "r", stdin);
	#endif
	ios::sync_with_stdio(false);
	// clock_t start,end;
	// start = clock();
	main0();
	// end = clock();
	// cout << (end - start) << endl;
	#ifndef ONLINE_JUDGE
		fclose(stdin);
	#endif
	return 0;
}

const int INF = 0x3f3f3f3f;
const int N = 1e6 + 5;
const int M = 1e5;
const int mod = 1e9 + 7;

vector <int> e[N];
int dfn[N], low[N], deep = 0;
int col[N], vis[N], cnt[N], deg[N];
int n, m;

stack <int> stk;
void tarjan (int u) {
	dfn[u] = low[u] = ++deep;
	vis[u] = 1;
	stk.push(u);
	for (int i = 0;i < e[u].size();i++) {
		int v = e[u][i];
		if (!dfn[v]) {
			tarjan(v);
			low[u] = min(low[u], low[v]);
		} else {
			 if (vis[v])
				 low[u] = min(low[u], low[v]);
		}
	}

	if (dfn[u] == low[u]) {
		col[0]++;
		while (true) {
			int t = stk.top(); stk.pop();
			col[t] = col[0];
			vis[t] = 0;
			if (t == u) break;
		}
	}
}

int main0 () {
	int T;
	cin >> T;
	while (T--) {
		cin >> n >> m;
		if (n <= 1) {
			cout << "NO" << endl;
			continue;
		}
		for (int i = 0;i <= n;i++) {
			e[i].clear();
			dfn[i] = 0;
			low[i] = 0;
			vis[i] = 0;
			col[i] = 0;
			cnt[i] = deg[i] = 0;
		}
		for (int i = 1;i <= m;i++) {
			int u, v;
			cin >> u >> v;
			if (u == v) continue;
			e[u].pb(v);
		}

		for (int i = 1;i <= n;i++) {
			if (!dfn[i]) tarjan(i);
		}

		int flag = 0;
		for (int i = 1;i <= n;i++) {//cout << i << ':' << col[i] << endl;
			cnt[col[i]]++;
			for (int j = 0;j < e[i].size();j++) {
				int v = e[i][j];
				if (col[i] != col[v]) deg[col[i]]++;
			}
			if (!deg[col[i]]) {
				flag = col[i];
				break;
			}
		}

		if (flag) {
			cout << "YES" << endl;
			cout << cnt[flag] << ' ' << n - cnt[flag] << endl;
			for (int i = 1;i <= n;i++) {
				if (col[i] == flag) cout << i << ' ';
			}
			cout << endl;
			for (int i = 1;i <= n;i++) {
				if (col[i] != flag) cout << i << ' ';
			}
			cout << endl;
		} else {
			cout << "NO" << endl;
		}
	}
}


#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define test cerr << '!' << endl;
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main0 ();
int main () {
	#ifndef ONLINE_JUDGE
		freopen("C:\\Users\\98497\\Desktop\\code\\file.in", "r", stdin);
	#endif
	ios::sync_with_stdio(false);
	// clock_t start,end;
	// start = clock();
	main0();
	// end = clock();
	// cout << (end - start) << endl;
	#ifndef ONLINE_JUDGE
		fclose(stdin);
	#endif
	return 0;
}

const int INF = 0x3f3f3f3f;
const int N = 1e6 + 5;
const int M = 1e5;
const int mod = 1e9 + 7;

vector <int> e[N];
int dfn[N], low[N];
int col[N], vis[N], cnt[N], deg[N];
int n, m;
int flag, deep;

stack <int> stk;
void tarjan (int u) {
	dfn[u] = low[u] = ++deep;
	vis[u] = 1;
	stk.push(u);
	for (int i = 0;i < e[u].size();i++) {
		int v = e[u][i];
		if (!dfn[v]) {
			tarjan(v);
			low[u] = min(low[u], low[v]);
		} else {
			 if (vis[v])
				 low[u] = min(low[u], low[v]);
		}
	}

	if (dfn[u] == low[u]) {
		col[0]++;
		while (true) {
			int t = stk.top(); stk.pop();
			col[t] = col[0];
			vis[t] = 0;
			if (t == u) break;
		}
	}
}

int main0 () {
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d", &n, &m);
		deep = 0;
		flag = 0;
		//col[0] = 0;
		for (int i = 0;i <= n;i++) {
			e[i].clear();
			dfn[i] = 0;
			low[i] = 0;
			vis[i] = 0;
			col[i] = 0;
			cnt[i] = deg[i] = 0;
		}
		for (int i = 1;i <= m;i++) {
			int u, v;
			scanf("%d%d", &u, &v);
			if (u == v) continue;
			e[u].pb(v);
		}

		for (int i = 1;i <= n;i++) {
			if (!dfn[i]) tarjan(i);
		}

		for (int i = 1;i <= n;i++) {
			//cout << i << ':' << col[i] << endl;
			cnt[col[i]]++;
		}

		for (int i = 1;i <= n;i++) {
			for (int j = 0;j < e[i].size();j++) {
				int v = e[i][j];
				if (col[i] != col[v]) deg[col[i]]++;
			}
			if ((!deg[col[i]]) && (cnt[col[i]] < n)) {
				flag = col[i];
				break;
			}
		}

		if (flag) {
			printf("YES\n");
			printf("%d %d\n", cnt[flag], n - cnt[flag]);
			for (int i = 1;i <= n;i++) {
				if (col[i] == flag) printf("%d ", i);
			} puts("");
			for (int i = 1;i <= n;i++) {
				if (col[i] != flag) printf("%d ", i);
			} puts("");
		} else {
			printf("NO\n");
		}
	}
}


#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define test cerr << '!' << endl;
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main0 ();
int main () {
	#ifndef ONLINE_JUDGE
		freopen("C:\\Users\\98497\\Desktop\\code\\file.in", "r", stdin);
	#endif
	ios::sync_with_stdio(false);
	// clock_t start,end;
	// start = clock();
	main0();
	// end = clock();
	// cout << (end - start) << endl;
	#ifndef ONLINE_JUDGE
		fclose(stdin);
	#endif
	return 0;
}

const int INF = 0x3f3f3f3f;
const int N = 1e6 + 5;
const int M = 1e5;
const int mod = 1e9 + 7;

vector <int> e[N];
int dfn[N], low[N];
int col[N], vis[N], cnt[N], deg[N];
int n, m;
int flag, deep;

stack <int> stk;
void tarjan (int u) {
	dfn[u] = low[u] = ++deep;
	vis[u] = 1;
	stk.push(u);
	for (int i = 0;i < e[u].size();i++) {
		int v = e[u][i];
		if (!dfn[v]) {
			tarjan(v);
			low[u] = min(low[u], low[v]);
		} else {
			 if (vis[v])
				 low[u] = min(low[u], low[v]);
		}
	}

	if (dfn[u] == low[u]) {
		col[0]++;
		while (true) {
			int t = stk.top(); stk.pop();
			col[t] = col[0];
			vis[t] = 0;
			if (t == u) break;
		}
	}
}

int main0 () {
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d", &n, &m);
		if (n == 1) {
			scanf("%d%d", &n, &m);
			printf("NO\n");
			continue;
		}

		deep = 0;
		flag = 0;
		col[0] = 0;
		for (int i = 0;i <= n;i++) {
			e[i].clear();
			dfn[i] = 0;
			low[i] = 0;
			//vis[i] = 0;
			//col[i] = 0;
			cnt[i] = deg[i] = 0;
		}
		for (int i = 1;i <= m;i++) {
			int u, v;
			scanf("%d%d", &u, &v);
			if (u == v) continue;
			e[u].pb(v);
		}

		for (int i = 1;i <= n;i++) {
			if (!dfn[i]) tarjan(i);
		}

		for (int i = 1;i <= n;i++) {
			//cout << i << ':' << col[i] << endl;
			cnt[col[i]]++;
		}

		for (int i = 1;i <= n;i++) {
			for (int j = 0;j < e[i].size();j++) {
				int v = e[i][j];
				if (col[i] != col[v]) deg[col[i]]++;
			}
			if ((!deg[col[i]]) && (cnt[col[i]] < n)) {
				flag = col[i];
				break;
			}
		}

		if (flag) {
			printf("YES\n");
			printf("%d %d\n", cnt[flag], n - cnt[flag]);
			for (int i = 1;i <= n;i++) {
				if (col[i] == flag) printf("%d ", i);
			} puts("");
			for (int i = 1;i <= n;i++) {
				if (col[i] != flag) printf("%d ", i);
			} puts("");
		} else {
			printf("NO\n");
		}
	}
}


#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define test cerr << '!' << endl;
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main0 ();
int main () {
	#ifndef ONLINE_JUDGE
		freopen("C:\\Users\\98497\\Desktop\\code\\file.in", "r", stdin);
	#endif
	ios::sync_with_stdio(false);
	// clock_t start,end;
	// start = clock();
	main0();
	// end = clock();
	// cout << (end - start) << endl;
	#ifndef ONLINE_JUDGE
		fclose(stdin);
	#endif
	return 0;
}

const int INF = 0x3f3f3f3f;
const int N = 1e6 + 5;
const int M = 1e5;
const int mod = 1e9 + 7;

vector <int> e[N];
int dfn[N], low[N];
int col[N], vis[N], cnt[N], deg[N];
int n, m;
int flag, deep;

stack <int> stk;
void tarjan (int u) {
	dfn[u] = low[u] = ++deep;
	vis[u] = 1;
	stk.push(u);
	for (int i = 0;i < e[u].size();i++) {
		int v = e[u][i];
		if (!dfn[v]) {
			tarjan(v);
			low[u] = min(low[u], low[v]);
		} else {
			 if (vis[v])
				 low[u] = min(low[u], low[v]);
		}
	}

	if (dfn[u] == low[u]) {
		col[0]++;
		while (true) {
			int t = stk.top(); stk.pop();
			col[t] = col[0];
			vis[t] = 0;
			if (t == u) break;
		}
	}
}

int main0 () {
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d", &n, &m);
		deep = 0;
		flag = 0;
		//col[0] = 0;
		for (int i = 0;i <= n;i++) {
			e[i].clear();
			dfn[i] = 0;
			low[i] = 0;
			vis[i] = 0;
			col[i] = 0;
			cnt[i] = deg[i] = 0;
		}
		for (int i = 1;i <= m;i++) {
			int u, v;
			scanf("%d%d", &u, &v);
			if (u == v) continue;
			e[u].pb(v);
		}

		for (int i = 1;i <= n;i++) {
			if (!dfn[i]) tarjan(i);
		}

		for (int i = 1;i <= n;i++) {
			//cout << i << ':' << col[i] << endl;
			cnt[col[i]]++;
		}

		for (int i = 1;i <= n;i++) {
			for (int j = 0;j < e[i].size();j++) {
				int v = e[i][j];
				if (col[i] != col[v]) deg[col[i]]++;
			}
		}

		for (int i = 1;i <= n;i++) {
			if ((!deg[col[i]]) && (cnt[col[i]] < n)) {
				flag = col[i];
				break;
			}
		}

		if (flag) {
			printf("YES\n");
			printf("%d %d\n", cnt[flag], n - cnt[flag]);
			for (int i = 1;i <= n;i++) {
				if (col[i] == flag) printf("%d ", i);
			} puts("");
			for (int i = 1;i <= n;i++) {
				if (col[i] != flag) printf("%d ", i);
			} puts("");
		} else {
			printf("NO\n");
		}
	}
}


#include <bits/stdc++.h>

using namespace std;

int ntest;
int n, m;
vector<int> adj[1000001];
int disc[1000001], low[1000001];
int cnt_v = 0;
stack<int> stk;
bool is_in_stack[1000001];
int scc[1000001], sz[1000001];
int cnt_scc = 0;
int out_deg[1000001];
vector<int> ans[2];

template <typename T>
inline T read() {
	T x = 0;
	T multiplier = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') {
			multiplier = -1;
		}
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 3) + (x << 1) + (ch & 15);
		ch = getchar();
	}
	return x * multiplier;
}

void tarjan(int u) {
	disc[u] = low[u] = ++cnt_v;
	stk.push(u);
	is_in_stack[u] = true;

	for (auto v : adj[u]) {
		if (!disc[v]) {
			tarjan(v);
			low[u] = min(low[u], low[v]);
		} else if (is_in_stack[v]) {
			low[u] = min(low[u], disc[v]);
		}
	}

	if (disc[u] == low[u]) {
		cnt_scc++;
		int x = 0;
		while (x ^ u) {
			x = stk.top();
			stk.pop();
			is_in_stack[x] = false;
			scc[x] = cnt_scc;
			sz[cnt_scc]++;
		}
	}
}

int main() {
	ntest = read<int>();
	while (ntest--) {
		n = read<int>(), m = read<int>();
		for (int i = 1; i <= n; i++) {
			adj[i].clear();
			disc[i] = 0, low[i] = 0;
			is_in_stack[i] = false;
			scc[i] = 0, sz[i] = 0;
		}
		while (!stk.empty()) {
			stk.pop();
		}
		ans[0].clear(), ans[1].clear();

		for (int i = 1; i <= m; i++) {
			int u = read<int>(), v = read<int>();
			adj[u].push_back(v);
		}

		for (int i = 1; i <= n; i++) {
			if (!disc[i]) {
				tarjan(i);
			}
		}

		for (int u = 1; u <= n; u++) {
			for (auto v : adj[u]) {
				if (scc[u] ^ scc[v]) {
					++out_deg[scc[u]];
				}
			}
		}

		if (sz[scc[1]] == n) {
			puts("NO");
			continue;
		}

		for (int i = 1; i <= cnt_scc; i++) {
			if (!out_deg[i] && sz[i]) {
				puts("YES");
				for (int j = 1; j <= n; j++) {
					ans[scc[j] == i].push_back(j);
				}

				printf("%d %d\n", ans[1].size(), ans[0].size());
				for (auto x : ans[1]) {
					printf("%d ", x);
				}
				puts("");
				for (auto x : ans[0]) {
					printf("%d ", x);
				}
				puts("");

				goto ans_found;
			}
		}
		puts("NO");
	ans_found:;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int ntest;
int n, m;
vector<int> adj[1000001];
int disc[1000001], low[1000001];
int cnt_v = 0;
stack<int> stk;
bool is_in_stack[1000001];
int scc[1000001], sz[1000001];
int cnt_scc = 0;
int out_deg[1000001];
vector<int> ans[2];

template <typename T>
inline T read() {
	T x = 0;
	T multiplier = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') {
			multiplier = -1;
		}
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 3) + (x << 1) + (ch & 15);
		ch = getchar();
	}
	return x * multiplier;
}

void tarjan(int u) {
	disc[u] = low[u] = ++cnt_v;
	stk.push(u);
	is_in_stack[u] = true;

	for (auto v : adj[u]) {
		if (!disc[v]) {
			tarjan(v);
			low[u] = min(low[u], low[v]);
		} else if (is_in_stack[v]) {
			low[u] = min(low[u], disc[v]);
		}
	}

	if (disc[u] == low[u]) {
		cnt_scc++;
		int x = 0;
		while (x ^ u) {
			x = stk.top();
			stk.pop();
			is_in_stack[x] = false;
			scc[x] = cnt_scc;
			sz[cnt_scc]++;
		}
	}
}

int main() {
	ntest = read<int>();
	while (ntest--) {
		n = read<int>(), m = read<int>();
		for (int i = 1; i <= n; i++) {
			adj[i].clear();
			disc[i] = 0, low[i] = 0;
			is_in_stack[i] = false;
			scc[i] = 0, sz[i] = 0;
			out_deg[i] = 0;
		}
		while (!stk.empty()) {
			stk.pop();
		}
		ans[0].clear(), ans[1].clear();

		for (int i = 1; i <= m; i++) {
			int u = read<int>(), v = read<int>();
			if (u ^ v) {
				adj[u].push_back(v);
			}
		}

		for (int i = 1; i <= n; i++) {
			if (!disc[i]) {
				tarjan(i);
			}
		}

		for (int u = 1; u <= n; u++) {
			for (auto v : adj[u]) {
				if (scc[u] ^ scc[v]) {
					++out_deg[scc[u]];
				}
			}
		}

		if (sz[scc[1]] == n) {
			puts("NO");
			continue;
		}

		for (int i = 1; i <= cnt_scc; i++) {
			if (!out_deg[i] && sz[i]) {
				puts("YES");
				for (int j = 1; j <= n; j++) {
					ans[scc[j] == i].push_back(j);
				}

				printf("%d %d\n", ans[1].size(), ans[0].size());
				for (auto x : ans[1]) {
					printf("%d ", x);
				}
				puts("");
				for (auto x : ans[0]) {
					printf("%d ", x);
				}
				puts("");

				goto ans_found;
			}
		}
		puts("NO");
	ans_found:;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int ntest;
int n, m;
vector<int> adj[1000001];
int disc[1000001], low[1000001];
int cnt_v = 0;
stack<int> stk;
bool is_in_stack[1000001];
int scc[1000001], sz[1000001];
int cnt_scc = 0;
int in_deg[1000001];
vector<int> ans[2];

template <typename T>
inline T read() {
	T x = 0;
	T multiplier = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') {
			multiplier = -1;
		}
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 3) + (x << 1) + (ch & 15);
		ch = getchar();
	}
	return x * multiplier;
}

void tarjan(int u) {
	disc[u] = low[u] = ++cnt_v;
	stk.push(u);
	is_in_stack[u] = true;

	for (auto v : adj[u]) {
		if (!disc[v]) {
			tarjan(v);
			low[u] = min(low[u], low[v]);
		} else if (is_in_stack[v]) {
			low[u] = min(low[u], disc[v]);
		}
	}

	if (disc[u] == low[u]) {
		cnt_scc++;
		int x = 0;
		while (x ^ u) {
			x = stk.top();
			stk.pop();
			is_in_stack[x] = false;
			scc[x] = cnt_scc;
			sz[cnt_scc]++;
		}
	}
}

int main() {
	ntest = read<int>();
	while (ntest--) {
		n = read<int>(), m = read<int>();

		cnt_v = cnt_scc = 0;
		for (int i = 1; i <= n; i++) {
			adj[i].clear();
			disc[i] = 0, low[i] = 0;
			is_in_stack[i] = false;
			scc[i] = 0, sz[i] = 0;
			in_deg[i] = 0;
		}
		while (!stk.empty()) {
			stk.pop();
		}
		ans[0].clear(), ans[1].clear();

		for (int i = 1; i <= m; i++) {
			int u = read<int>(), v = read<int>();
			if (u ^ v) {
				adj[u].push_back(v);
			}
		}

		for (int i = 1; i <= n; i++) {
			if (!disc[i]) {
				tarjan(i);
			}
		}

		for (int u = 1; u <= n; u++) {
			for (auto v : adj[u]) {
				if (scc[u] ^ scc[v]) {
					++in_deg[scc[v]];
				}
			}
		}

		if (sz[scc[1]] == n) {
			puts("NO");
			continue;
		}

		for (int i = 1; i <= cnt_scc; i++) {
			if (!in_deg[i] && sz[i]) {
				puts("YES");
				for (int j = 1; j <= n; j++) {
					ans[scc[j] == i].push_back(j);
				}

				printf("%d %d\n", ans[0].size(), ans[1].size());
				for (auto x : ans[0]) {
					printf("%d ", x);
				}
				puts("");
				for (auto x : ans[1]) {
					printf("%d ", x);
				}
				puts("");

				goto ans_found;
			}
		}
		puts("NO");
	ans_found:;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int ntest;
int n, m;
vector<int> adj[1000001];
int disc[1000001], low[1000001];
int cnt_v = 0;
stack<int> stk;
bool is_in_stack[1000001];
int scc[1000001], sz[1000001];
int cnt_scc = 0;
int in_deg[1000001];
vector<int> ans[2];

template <typename T>
inline T read() {
	T x = 0;
	T multiplier = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') {
			multiplier = -1;
		}
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 3) + (x << 1) + (ch & 15);
		ch = getchar();
	}
	return x * multiplier;
}

void tarjan(int u) {
	disc[u] = low[u] = ++cnt_v;
	stk.push(u);
	is_in_stack[u] = true;

	for (auto v : adj[u]) {
		if (!disc[v]) {
			tarjan(v);
			low[u] = min(low[u], low[v]);
		} else if (is_in_stack[v]) {
			low[u] = min(low[u], disc[v]);
		}
	}

	if (disc[u] == low[u]) {
		cnt_scc++;
		int x = 0;
		while (x ^ u) {
			x = stk.top();
			stk.pop();
			is_in_stack[x] = false;
			scc[x] = cnt_scc;
			sz[cnt_scc]++;
		}
	}
}

int main() {
	ntest = read<int>();
	while (ntest--) {
		n = read<int>(), m = read<int>();
		for (int i = 1; i <= n; i++) {
			adj[i].clear();
			disc[i] = 0, low[i] = 0;
			is_in_stack[i] = false;
			scc[i] = 0, sz[i] = 0;
		}
		while (!stk.empty()) {
			stk.pop();
		}
		ans[0].clear(), ans[1].clear();

		for (int i = 1; i <= m; i++) {
			int u = read<int>(), v = read<int>();
			adj[u].push_back(v);
		}

		for (int i = 1; i <= n; i++) {
			if (!disc[i]) {
				tarjan(i);
			}
		}

		for (int u = 1; u <= n; u++) {
			for (auto v : adj[u]) {
				if (scc[u] ^ scc[v]) {
					++in_deg[scc[v]];
				}
			}
		}

		if (sz[scc[1]] == n) {
			puts("NO");
			continue;
		}

		for (int i = 1; i <= cnt_scc; i++) {
			if (!in_deg[i] && sz[i]) {
				puts("YES");
				for (int j = 1; j <= n; j++) {
					ans[scc[j] == i].push_back(j);
				}

				printf("%d %d\n", ans[0].size(), ans[1].size());
				for (auto x : ans[0]) {
					printf("%d ", x);
				}
				puts("");
				for (auto x : ans[1]) {
					printf("%d ", x);
				}
				puts("");

				goto ans_found;
			}
		}
		puts("NO");
	ans_found:;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int ntest;
int n, m;
vector<int> adj[1000001];
int disc[1000001], low[1000001];
int cnt_v = 0;
stack<int> stk;
bool is_in_stack[1000001];
int scc[1000001], sz[1000001];
int cnt_scc = 0;
int out_deg[1000001];
vector<int> ans[2];

template <typename T>
inline T read() {
	T x = 0;
	T multiplier = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') {
			multiplier = -1;
		}
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 3) + (x << 1) + (ch & 15);
		ch = getchar();
	}
	return x * multiplier;
}

void tarjan(int u) {
	disc[u] = low[u] = ++cnt_v;
	stk.push(u);
	is_in_stack[u] = true;

	for (auto v : adj[u]) {
		if (!disc[v]) {
			tarjan(v);
			low[u] = min(low[u], low[v]);
		} else if (is_in_stack[v]) {
			low[u] = min(low[u], disc[v]);
		}
	}

	if (disc[u] == low[u]) {
		cnt_scc++;
		int x = 0;
		while (x ^ u) {
			x = stk.top();
			stk.pop();
			is_in_stack[x] = false;
			scc[x] = cnt_scc;
			sz[cnt_scc]++;
		}
	}
}

int main() {
	ntest = read<int>();
	while (ntest--) {
		n = read<int>(), m = read<int>();
		for (int i = 1; i <= n; i++) {
			adj[i].clear();
			disc[i] = 0, low[i] = 0;
			is_in_stack[i] = false;
			scc[i] = 0, sz[i] = 0;
			out_deg[i] = 0;
		}
		while (!stk.empty()) {
			stk.pop();
		}
		ans[0].clear(), ans[1].clear();

		for (int i = 1; i <= m; i++) {
			int u = read<int>(), v = read<int>();
			adj[u].push_back(v);
		}

		for (int i = 1; i <= n; i++) {
			if (!disc[i]) {
				tarjan(i);
			}
		}

		for (int u = 1; u <= n; u++) {
			for (auto v : adj[u]) {
				if (scc[u] ^ scc[v]) {
					++out_deg[scc[u]];
				}
			}
		}

		if (sz[scc[1]] == n) {
			puts("NO");
			continue;
		}

		for (int i = 1; i <= cnt_scc; i++) {
			if (!out_deg[i] && sz[i]) {
				puts("YES");
				for (int j = 1; j <= n; j++) {
					ans[scc[j] == i].push_back(j);
				}

				printf("%d %d\n", ans[1].size(), ans[0].size());
				for (auto x : ans[1]) {
					printf("%d ", x);
				}
				puts("");
				for (auto x : ans[0]) {
					printf("%d ", x);
				}
				puts("");

				goto ans_found;
			}
		}
		puts("NO");
	ans_found:;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<sstream>
#include<cctype>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<set>
#include<functional>
#define in(x) x=read()
#define qr read()
#define int ll
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
namespace fastIO
{
    #define BUF_SIZE 100000
    bool IOerror=0;
    inline char nc()
	{
        static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
        if (p1==pend){
            p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);
            if (pend==p1){IOerror=1;return -1;}
        }
        return *p1++;
    }
    inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
    inline ll read()
	{
        bool sign=0; char ch=nc();ll x=0;
        for (;blank(ch);ch=nc());
        if (IOerror)return 0;
        if (ch=='-')sign=1,ch=nc();
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
        if (sign)x=-x;
        return x;
    }
    #undef BUF_SIZE
};
using namespace fastIO;
int low[1000010],dfn[1000100],ins[1000010],top=0,s[1000010],tim=0,now=0,belong[1000010];
vector<int>e[1000010],ans1,ans2;
void tarjan(int x)
{
	low[x]=dfn[x]=++tim;
	ins[x]=1;
	s[++top]=x;
	for(auto i:e[x])
	{
		if(!dfn[i])
		{
			tarjan(i);
			low[x]=min(low[x],low[i]);
		}
		else if(ins[i])low[x]=min(low[x],dfn[i]);
	}
	if(low[x]==dfn[x])
	{
		now++;
		int cnt=0;
		do
		{
			cnt=s[top--];
			belong[cnt]=now;
			ins[cnt]=0;
		}while(cnt!=x);
	}
}
void clear(int n)
{
	for(int i=1;i<=n;i++)
	{
		e[i].clear();
		low[i]=ins[i]=dfn[i]=belong[i]=0;
	}
	top=tim=now=0;
	ans1.clear(),ans2.clear();
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int t=qr;
	while(t--)
	{
		int n=qr,m=qr;
		for(int i=1;i<=m;i++)
		{
			int x=qr,y=qr;
			e[x].push_back(y);
		}
		for(int i=1;i<=n;i++)
		{
			if(!dfn[i])tarjan(i);
		}
		if(now==1)
		{
			puts("NO");
			clear(n);
			continue;
		}
		puts("YES");
		int sum1=0,sum2=0;
		for(int i=1;i<=n;i++)
		{
			if(belong[i]==1)sum1++,ans1.push_back(i);
			else sum2++,ans2.push_back(i);
		}
		cout<<sum1<<' '<<sum2<<'\n';
		for(auto i:ans1)cout<<i<<' ';cout<<'\n';
		for(auto i:ans2)cout<<i<<' ';cout<<'\n';
		clear(n);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define de(x) cout<<#x<<" = "<<x<<'\n'
#define dd(x) cout<<#x<<" = "<<x<<' '
#define mp make_pair
#define pb push_back

typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 1e6 + 15;
vector<int> g[N];
int bel[N], col, dfn[N], low[N], tme, s[N], tp;

void tarjan( int u ) {
	dfn[u] = low[u] = ++tme;
	s[++tp] = u;
	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]);
		}
		else if ( !bel[v] )
			low[u] = min( low[u], dfn[v] );
	}
	if ( dfn[u] == low[u] ) {
		bel[u] = ++col;
		while ( s[tp] != u )
			bel[s[tp--]] = col;
		tp --;
	}
}

void init( int n ) {
	for ( int i = 0; i < n+2; i ++ ) {
		g[i].clear();
		dfn[i] = low[i] = bel[i] = 0;
	}
	tp = col = tme = 0;
}

int main() {
	int T;
	scanf("%d", &T);
	while ( T -- ) {
		int n, m;
		scanf("%d%d", &n, &m);
		init(n);
		for ( int i = 0, u, v; i < m; i ++ ) {
			scanf("%d%d", &u, &v);
			if ( u == v ) continue;
			g[u].pb(v);
		}
		for ( int i = 1; i <= n; i ++ )
			if ( !dfn[i] ) tarjan(i);
		if ( col == 1 ) puts("No");
		else {
			puts("Yes");
			int ans = 0;
			for ( int i = 1; i <= n; i ++ )
				ans += bel[i]==1;
			printf("%d %d\n", ans, n-ans);
			for ( int i = 1; i <= n; i ++ )
				if ( bel[i] == 1 ) printf("%d ", i);
			puts("");
			for ( int i = 1; i <= n; i ++ )
				if ( bel[i] != 1 ) printf("%d ", i);
			puts("");
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define de(x) cout<<#x<<" = "<<x<<'\n'
#define dd(x) cout<<#x<<" = "<<x<<' '
#define mp make_pair
#define pb push_back

typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 15;
vector<int> g[N];
int bel[N], col, dfn[N], low[N], tme, s[N], tp;

void tarjan( int u ) {
	dfn[u] = low[u] = ++tme;
	s[++tp] = u;
	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]);
		}
		else if ( !bel[v] )
			low[u] = min( low[u], dfn[v] );
	}
	if ( dfn[u] == low[u] ) {
		bel[u] = ++col;
		while ( s[tp] != u )
			bel[s[tp--]] = col;
		tp --;
	}
}

void init( int n ) {
	for ( int i = 0; i < n+2; i ++ ) {
		g[i].clear();
		dfn[i] = low[i] = bel[i] = 0;
	}
	tp = col = tme = 0;
}

int main() {
	int T;
	scanf("%d", &T);
	while ( T -- ) {
		int n, m;
		scanf("%d%d", &n, &m);
		init(n);
		for ( int i = 0, u, v; i < m; i ++ ) {
			scanf("%d%d", &u, &v);
			if ( u == v ) continue;
			g[u].pb(v);
		}
		for ( int i = 1; i <= n; i ++ )
			if ( !dfn[i] ) tarjan(i);
		if ( col == 1 ) puts("No");
		else {
			puts("Yes");
			int ans = 0;
			for ( int i = 1; i <= n; i ++ )
				ans += bel[i]==1;
			printf("%d %d\n", ans, n-ans);
			for ( int i = 1; i <= n; i ++ )
				if ( bel[i] == 1 ) printf("%d ", i);
			puts("");
			for ( int i = 1; i <= n; i ++ )
				if ( bel[i] != 1 ) printf("%d ", i);
			puts("");
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

typedef long double ld;
typedef long long ll;

const int MAX_N = 1e6+10;
const ll INF = 1000000000000000001LL;
const ll MOD = 1e9+7;

int t, n, m, cnt,verticesScc[MAX_N], degout[MAX_N];
vector<int>g[MAX_N],g1[MAX_N],scc[MAX_N], ans, ans1;
vector<int>tSort;
bool mark[MAX_N];

void topologicalSort(int v) {
    mark[v] = true;
    for(int u:g[v])
        if(!mark[u])
            topologicalSort(u);
    tSort.push_back(v);
}

void dfs(int v) {
    mark[v] = true;
    scc[cnt].push_back(v);
    verticesScc[v] = cnt;
    for(int u:g1[v])
        if(!mark[u])
            dfs(u);
}

void SCC() {
    for(int i = 1 ; i <= n ; i++)
        if(!mark[i])
            topologicalSort(i);
    reverse(tSort.begin(), tSort.end());
    for(int i = 1 ; i <= n ; i++)
        mark[i] = false;

    for(int v:tSort)
        if(!mark[v]) {
            cnt++;
            dfs(v);
        }
}

int main() {
    //ios_base::sync_with_stdio(false);
    //cin>>t;
    scanf("%d", &t);
    while(t--) {
        //cin>>n>>m;
        scanf("%d %d", &n, &m);
        for(int i = 1 ; i <= n ; i++) {
            verticesScc[i] = 0;
            g[i].clear();
            g1[i].clear();
            scc[i].clear();
            mark[i] = 0;
            degout[i] = 0;
        }
        cnt = 0;
        tSort.clear();
        ans1.clear();
        ans.clear();
        for(int i = 1 ; i <= m ; i++) {
            int a, b;
            //cin>>a>>b;
            scanf("%d %d", &a, &b);
            g[a].push_back(b);
            g1[b].push_back(a);
        }
        SCC();
        if(cnt == 1) {
            //cout<<"No"<<endl;
            printf("No\n");
            continue;
        }
        //cout<<"Yes"<<endl;
        printf("Yes\n");
        for(int i = 1 ; i <= n ; i++) {
            for(int v: g[i]) {
                if(verticesScc[i] == verticesScc[v])
                    continue;
                degout[verticesScc[i]]++;
            }
        }

        for(int i = 1 ; i <= cnt ; i++) {
            if(degout[i] == 0) {
                for(int v: scc[i])
                    ans.push_back(v);
            }
            else {
                for(int v: scc[i])
                    ans1.push_back(v);
            }
        }
        printf("%lu %lu\n", ans.size(), ans1.size());
        //cout<<ans.size()<<" "<<ans1.size()<<endl;
        for(int v: ans)
            printf("%d ", v);
            //cout<<v<<" ";
        //cout<<endl;
        printf("\n");
        for(int v: ans1)
            printf("%d ", v);
            //cout<<v<<" ";
        //cout<<endl;
        printf("\n");

    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

typedef long double ld;
typedef long long ll;

const int MAX_N = 1e6+10;
const ll INF = 1000000000000000001LL;
const ll MOD = 1e9+7;

int t, n, m, cnt,verticesScc[MAX_N], degout[MAX_N];
vector<int>g[MAX_N],g1[MAX_N],scc[MAX_N], ans, ans1;
vector<int>tSort;
bool mark[MAX_N];

void topologicalSort(int v) {
    mark[v] = true;
    for(int u:g[v])
        if(!mark[u])
            topologicalSort(u);
    tSort.push_back(v);
}

void dfs(int v) {
    mark[v] = true;
    scc[cnt].push_back(v);
    verticesScc[v] = cnt;
    for(int u:g1[v])
        if(!mark[u])
            dfs(u);
}

void SCC() {
    for(int i = 1 ; i <= n ; i++)
        if(!mark[i])
            topologicalSort(i);
    reverse(tSort.begin(), tSort.end());
    for(int i = 1 ; i <= n ; i++)
        mark[i] = false;

    for(int v:tSort)
        if(!mark[v]) {
            cnt++;
            dfs(v);
        }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin>>t;
    while(t--) {
        cin>>n>>m;
        for(int i = 1 ; i <= n ; i++) {
            verticesScc[i] = 0;
            g[i].clear();
            g1[i].clear();
            scc[i].clear();
            mark[i] = 0;
            degout[i] = 0;
        }
        cnt = 0;
        tSort.clear();
        ans1.clear();
        ans.clear();
        for(int i = 1 ; i <= m ; i++) {
            int a, b;
            cin>>a>>b;
            g[a].push_back(b);
            g1[b].push_back(a);
        }
        SCC();
        if(cnt == 1) {
            cout<<"No"<<endl;
            continue;
        }
        for(int i = 1 ; i <= n ; i++) {
            for(int v: g[i]) {
                if(verticesScc[i] == verticesScc[v])
                    continue;
                degout[verticesScc[i]]++;
            }
        }

        for(int i = 1 ; i <= cnt ; i++) {
            if(degout[i] == 0) {
                for(int v: scc[i])
                    ans.push_back(v);
            }
            else {
                for(int v: scc[i])
                    ans1.push_back(v);
            }
        }
        cout<<ans.size()<<" "<<ans1.size()<<endl;
        for(int v: ans)
            cout<<v<<" ";
        cout<<endl;
        for(int v: ans1)
            cout<<v<<" ";
        cout<<endl;

    }
}