#include <iostream>
#include <map>
#include <string>
using namespace std;
int shaungshengci()
{
map<string, int> se;
int ret = 0;
int num = 0;
cin >> num;
for (int j = 0; j < num; j++)
{
string a;
cin >> a;
int len = a.size();
string c;
c.assign(a.rbegin(), a.rend());
c += c;
a += a;
string::iterator ie = c.begin();
string::iterator it = a.begin();
for (; a.end() - it>len && ret != 1; it++,ie++)
{
string b(it, it + len);
pair<map<string,int>::iterator,bool> pa = se.insert(pair<string, int>(b, j));
if (pa.second == false)
{
if (pa.first->second != j)
{
ret = 1;
break;
}
}
string d(ie, ie + len);
pair<map<string, int>::iterator,bool> pb = se.insert(pair<string, int>(d, -1));
if (pb.second == false)
{
if (pb.first->second != j)
{
ret = 1;
break;
}
}
}
}
return ret;
}
int main()
{
int size = 0;
cin >> size;
for (int i = 0; i < size; i++)
{
int ret = shaungshengci();
if (ret == 1)
{
cout << "Yeah" << endl;
}
else
{
cout << "Sad";
}
}
return 0;
}
考完后才想到的 不知道有没有错误 没办法验证,,,,,