#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
while(cin >> n, n != 0)
{
string tree;
cin >> tree;
string root;
root = tree[0];
string left;
string right;
for(int i = 1; i < tree.size(); ++i)
{
if(tree[i] > tree[0])
right += tree[i];
else
left += tree[i];
}
for(int i = 0; i < n; ++i)
{
string temp;
cin >> temp;
string a, b, r;
r = temp[0];
for(int i = 1; i < temp.size(); ++i)
{
if(temp[i] > temp[0])
a += temp[i];
else
b += temp[i];
}
if(a == right && b == left && r == root)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
}
转载于:https://my.oschina.net/u/196018/blog/383778