#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
using namespace std;
int main()
{
string input;
int poker[54];
int n=0;
while(cin>>input)
{
int k=input.length();
for(int i=0;i<k,i++)
{
if(input[i]=='J')
poker[n++]=11;
if(input[i]=='Q')
poker[n++]=12;
if(input[i]=='K')
poker[n++]=13;
if(input[i]>49&&input[i]<58)
{
poker[n++]=input[i]-'0';
}
if(input[i]==49)
{
if(input[i+1]=='0')
{
poker[n++]=10;
}
else
{
poker[n++]=1;
}
}
}
}
if(n!=52)
{
cout<<"-1";
return 0;
}
vector<int>pai;
for(int i=0;i<52;i++)
{
if(pai.size()<poker[i])
{
pai.push_back(poker[i]);
}
else
{
pai.insert(pai.begin()+poker[i],poker[i])//注意插入的位置
}
}
for (int i = 0; i < pai.size(); i++)
{
if (pai[i] == 11) cout << 'J' << ' ';
if (pai[i] == 12) cout << 'Q' << ' ';
if (pai[i] == 13) cout << 'K' << ' ';
if (pai[i] >= 1 && pai[i] <= 10) cout << pai[i] << ' ';
}
return 0;
}