#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector <int> a(26, -1);
vector <int> b(26, -1);
vector <int> cnt(26);
for (int i=0; i<a.size(); i++){
cout<<a[i]<<endl;
}
for (int i = 0; i < n; i++)
{
vector <bool> kek(26);
string s;
cin >> s;
for (auto &c : s)
{
c -= 'a';
cnt[c]++;
if (kek[c])
{
cout << "NO\n";
return 0;
}
else
{
kek[c] = true;
}
}//判有没有重复字母
for (int i = 0; i + 1 < (int) s.size(); i++)
{
if (a[s[i]] != -1 && a[s[i]] != s[i + 1])
{
cout << "NO\n";
return 0;
}
else
{
if (b[s[i + 1]] != -1 && b[s[i + 1]] != s[i])
{
cout << "NO\n";
return 0;
}
a[s[i]] = s[i + 1];
b[s[i + 1]] = s[i];
}
}
}//判相同字母出现时的前驱和后缀是否相同
vector <string> res;
vector <bool> vis(26);
for (int i = 0; i < 26; i++)
{
if (b[i] == -1 && cnt[i])
{
string s = "";
int x = i;
while (x != -1)
{
vis[x] = 1;
s += (x + 'a');
x = a[x];
}
res.push_back(s);
}
}
for (int i = 0; i < 26; i++)
{
if (!vis[i] && cnt[i])
{
cout << "NO\n";
return 0;
}
}//判回文如abc cba, pre[a]=b, pre[b]=a, suf[a]=b, suf[b]=a,但是其实这时-1不是没有遇到前缀,而是表示第一位和第二位,觉得可以用-2 -1分层表示
sort(res.begin(), res.end(), [] (string a, string b)
{
return a + b < b + a;
});
for (auto c : res) cout << c;
cout << '\n';
}