#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using
namespace
std;
const
int
N=2e3+100;
int
T,n,tot;
int
head[N],ver[2*N],Next[2*N];
int
rev[N],pre[N],cnt1[N],cnt2[N],cnt3[N],from[N],to[N],p[N][N],header[N][N],tailer[N][N];
bool
pd[N];
void
add(
int
x,
int
y)
{
ver[++tot]=y,Next[tot]=head[x],head[x]=tot;
ver[++tot]=x,Next[tot]=head[y],head[y]=tot;
}
void
check(
int
x,
int
root)
//root就是数字的起点
{
for
(
int
i=head[x],y=ver[i];i;i=Next[i],y=ver[i])
if
(y!=pre[x])
{
pre[y]=x,pd[y]=1;
if
(x!=root)
{
if
(p[x][y]==x || !p[x][y])
pd[y]=0;
if
(tailer[x][y]==from[x] && header[x][pre[x]]==to[x] && cnt1[x]*2+cnt2[x]+cnt3[x]-2>0)
pd[y]=0;
if
(tailer[x][y]==pre[x])
pd[y]=0;
}
//中间边