特判没有出现的孤立点
#include<bits/stdc++.h>
#define LL long long
#define x first
#define y second
#define de(x) cout<<#x<<" = "<<x<<" "
#define deg(x) cout<<#x<<" = "<<x<<endl
using namespace std;
const int N=30;
typedef pair<int,int> PII;
int n;
int p[N],st[N],din[N],dout[N];
int find(int x)
{
if(x!=p[x])p[x]=find(p[x]);
return p[x];
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
for(int i=0;i<26;i++)p[i]=i;
memset(st,0,sizeof st);
memset(din,0,sizeof din);
memset(dout,0,sizeof dout);
cin>>n;
for(int i=1;i<=n;i++)
{
string s;
cin>>s;
int a=s[0]-'a',b=s[s.size()-1]-'a';
st[a]=st[b]=1;
dout[a]++,din[b]++;
p[find(b)]=find(a);
}
int ok=1;
int ft=0,ed=0;
for(int i=0;i<26;i++)
{
if(din[i]!=dout[i])
{
if(din[i]==dout[i]+1)ft++;
else if(din[i]+1==dout[i])ed++;
else
{
ok=0;
break;
}
}
}
if(ok&&!(!ft&&!ed||ft==1&&ed==1))ok=0;
int rp=-1;
for(int i=0;i<26;i++)
{
if(st[i])
{
if(rp==-1)rp=find(i);
else if(rp!=find(i))
{
ok=0;
break;
}
}
}
if(ok)cout<<"Ordering is possible."<<endl;
else cout<<"The door cannot be opened."<<endl;
}
return 0;
}