#include<iostream>
using namespace std;
int main()
{
char a[18];
int t;
cin>>t;
for(int i=0;i<t;i++)
{
cin>>a;
cout<<"He/She is from ";
if(a[0]=='3')
{
if(a[1]=='3')
cout<<"Zhejiang";
else
cout<<"Shanghai";
}
else if(a[0]=='8')
{
if(a[1]=='1')
cout<<"Hong Kong";
else
cout<<"Macao";
}
else if(a[0]=='1')
cout<<"Beijing";
else if(a[0]=='2')
cout<<"Liaoning";
else if(a[0]=='5')
cout<<"Tibet";
else
cout<<"Taiwan";
cout<<",and his/her birthday is on ";
cout<<a[10]<<a[11]<<','<<a[12]<<a[13]<<','<<a[6]<<a[7]<<a[8]<<a[9]<<" based on the table."<<endl;
}
}
using namespace std;
int main()
{
char a[18];
int t;
cin>>t;
for(int i=0;i<t;i++)
{
cin>>a;
cout<<"He/She is from ";
if(a[0]=='3')
{
if(a[1]=='3')
cout<<"Zhejiang";
else
cout<<"Shanghai";
}
else if(a[0]=='8')
{
if(a[1]=='1')
cout<<"Hong Kong";
else
cout<<"Macao";
}
else if(a[0]=='1')
cout<<"Beijing";
else if(a[0]=='2')
cout<<"Liaoning";
else if(a[0]=='5')
cout<<"Tibet";
else
cout<<"Taiwan";
cout<<",and his/her birthday is on ";
cout<<a[10]<<a[11]<<','<<a[12]<<a[13]<<','<<a[6]<<a[7]<<a[8]<<a[9]<<" based on the table."<<endl;
}
}