#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll,ll>;
using vpll = vector<pll>;
using vs = vector<string>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const ld eps = 1e-9;
#define sz(c) ll((c).size())
#define pb(c) push_back(c)
#define all(c) begin(c),end(c)
#define mp make_pair
#define xx first
#define yy second
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })
ll adj[18][18] = {0};
map<char,ll> inds;
ll getInd(char a){
if(!inds.contains(a)) inds[a] = sz(inds);
return inds[a];
}
ll solve(ll curr, vl &cols, vl &rem){
if(curr == 18) return 1;
FOR(i,0,3){
if(rem[i] == 0) continue;
ll pos=1;
FOR(j,0,curr) if(adj[curr][j] && cols[j] == i) pos = 0;
if(!pos) continue;
cols[curr] = i; rem[i]--;
if(solve(curr+1, cols, rem)) return 1;
rem[i]++;
}
return 0;
}
int main() { cin.sync_with_stdio(0); cin.tie(0);
ll n; cin >> n;
FOR(i,0,n){
string a; cin >> a;
FOR(j,1,3) FOR(k,0,j){
if(getInd(a[j]) >= 18 || getInd(a[k]) >= 18){
cout << "0\n";
return 0;
}
adj[getInd(a[k])][getInd(a[j])] = 1;
adj[getInd(a[j])][getInd(a[k])] = 1;
}
}
FOR(i,'a','z'+1) if(getInd(i) == 17) break;
vl cols(18);
vl rem(3,6);
if(!solve(0, cols, rem)) cout << "0\n";
else{
vvl die(3);
for(auto [k,v] : inds){
die[cols[v]].pb(k);
}
FOR(i,0,3){
FOR(j,0,6) cout << (char) die[i][j];
cout << " ";
}
cout << endl;
}
}