#include <bits/stdc++.h>
using namespace std;
#define ma 1e5
const int maxn = ma + 7;
typedef long long ll;
typedef unsigned long long ull;
//#define int long long
//#define fo(i,n,m) for(int i=n;i<=m;i++)
string a;
int n = 4, maxx = -1;
map<char, int> q;
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//freopen(".in","r",stdin);
freopen("P1598.out", "w", stdout);
while (n--) {
getline(cin, a);
// cout << a;
for (int i = 0; i < a.length(); i++) {
if (a[i] >= 'A' && a[i] <= 'Z') {
// cout << 1;
q[a[i]]++;
}
}
}
for (char i = 'A'; i <= 'Z'; i++) {
maxx = max(maxx, q[i]);
}
for (; maxx >= 1; maxx--) {
for (char i = 'A'; i < 'Z'; i++) {
// cout << i;
if (maxx == q[i]) {
cout << '*';
q[i]--;
} else {
cout << ' ';
}
cout << ' ';
}
if (maxx == q['Z']) {
cout << '*';
q['Z']--;
} else {
cout << ' ';
}
cout << "\n";
}
for (char i = 'A'; i < 'Z'; i++) {
cout << i << ' ';
}
cout << 'Z';
// cout << q['O'] << '\n';
return 0;
}