#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
str s[8];
bool check(str a,str b,str c){
int cnt=0, arr[9]={-1,-1,-1,-1,-1,-1,-1};
for(int x=0;x<3;x++){
str now="";
now+=a[x];
now+=b[x];
now+=c[x];
for(int i=1;i<=6;i++){
if(s[i]==now&&s[i]!=a&&s[i]!=b&&s[i]!=c&&arr[i]==-1){
cnt++;
arr[i]=1;
break;
}
}
}
if(cnt==3)
return true;
return false;
}
int main(){
for(int i=1;i<=6;i++){
cin >>s[i];
}
for(int i=1;i<=6;i++){
for(int j=1;j<=6;j++){
for(int k=1;k<=6;k++){
if(i==j||j==k||i==k) continue;
if(check(s[i],s[j],s[k])) {
cout <<s[i]<<endl<<s[j]<<endl<<s[k];
return 0;
}
}
}
}
cout <<0;
return 0;
}