#include
#include
#include
using namespace std;
int n,m,T,cnt,tot,sum,top;
int to[1000010],next[1000010],head[2010],dep[2010],low[2010],ins[2010],sta[2010],bel[2010];
int p[2010],pa[20010],pb[20010];
int rd()
{
int ret=0,f=1; char gc=getchar();
while(gc<‘0‘||gc>‘9‘) {if(gc==‘-‘)f=-f; gc=getchar();}
while(gc>=‘0‘&&gc<=‘9‘) ret=ret*10+gc-‘0‘,gc=getchar();
return ret*f;
}
void tarjan(int x)
{
dep[x]=low[x]=++tot,ins[x]=1,sta[++top]=x;
for(int i=head[x];i!=-1;i=next[i])
{
if(!dep[to[i]]) tarjan(to[i]),low[x]=min(low[x],low[to[i]]);
else if(ins[to[i]]) low[x]=min(low[x],dep[to[i]]);
}
if(dep[x]==low[x])
{
int t;
sum++;
do
{
t=sta[top--],ins[t]=0,bel[t]=sum;
}while(t!=x);
}
}
void add(int a,int b)
{
to[cnt]=b,next[cnt]=head[a],head[a]=cnt++;
}
void work()
{
memset(head,-1,sizeof(head));
memset(dep,0,sizeof(dep));
n=rd(),m=rd(),cnt=tot=sum=0;
int i,j,a,b;
for(i=0;i3*n-6)
{
printf("NO\n");
return ;
}
for(i=0;ipb[i]) swap(pa[i],pb[i]);
if(pa[i]+1==pb[i]) continue;
for(j=0;jpa[i]&&pa[j]pb[i])||(pa[j]pa[i]&&pb[j]