// Problem: D - Message from Aliens
// Contest: AtCoder - ZONe Energy Programming Contest
// URL: https://atcoder.jp/contests/zone2021/tasks/zone2021_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll> 
#define all(x) (x).begin() , (x).end()

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

void dbg(){
	cerr << endl;
}
template<typename Head , typename... Tail>
void dbg(Head h , Tail... t){
	cerr << h << " ";
	dbg(t...);
}

#ifdef EMBI_DEBUG
#define debug(...) cerr << "(" << #__VA_ARGS__  << "): ", dbg(__VA_ARGS__)
#else 
#define debug(...)
#endif

const int max_n = 1e5 + 9;
const int mod = 1e9 + 7;
const int inf = 1e9;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
void solve(){
	string s;
	cin >> s;
	
	int n = s.size();
	deque<char> d;
	int curr = 0;
	for(int i = 0 ; i < n ; i++) {
		if(s[i] == 'R') {
			curr ^= 1;
		}
		else {
			if(curr) {
				d.push_front(s[i]);
			}
			else d.push_back(s[i]);
		}
	}
	
	string str;
	while(!d.empty()) {
		if(curr) {
			str += d.back();
			d.pop_back();
		}
		else {
			str += d.front();
			d.pop_front();
		}
	}
	
	stack<char> st;
	for(auto it : str) {
		if(st.empty()) {
			st.push(it);
		}
		else {
			if(st.top() == it)st.pop();
			else st.push(it);
		}
	}
	
	str = "";
	while(!st.empty()) {
		str += st.top();
		st.pop();
	}
	
	reverse(all(str));
	cout << str << "\n";
}
signed main(){
	int t = 1;
	// cin >> t;
	for(int i = 1 ; i <= t ; i++){
		// cout << "Case #" << i << ": ";
		solve();
	}
}

#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define fi first
#define se second
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll mod_998244353 = 998244353;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

//using lll=boost::multiprecision::cpp_int;
//using Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<128>>;//仮数部が1024桁
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll mypow(ll x, ll n, const ll &p = -1)
{ //x^nをmodで割った余り

	if (p != -1)
	{
		x =(x%p+p)%p;
	}
	ll ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

using namespace std;
//using namespace atcoder;

void ng(){
	cout<<"UNSOLVABLE\n";
	exit(0);
}
void solve()
{	
	set<char>st;
	vector<string>s(3);
	rep(i,3)cin>>s[i];

	rep(i,3){
		rep(j,s[i].size()){
			st.emplace(s[i][j]);
		}
	}
	if(st.size()>10){
		ng();
	}
	vector<int>v(10);
	rep(i,10)v[i]=i;
	bool ok=false;
	do{
		vector<int>used(26,-1);
		int pos=0;
		rep(i,3){
			rep(j,s[i].size()){
				if(used[s[i][j]-'a']==-1){
					used[s[i][j]-'a']=v[pos++];
				}
			}
		}
		bool no=false;
		ll x[3]={};
		rep(i,3){
			if(used[s[i][0]-'a']==0)no=true;
		}
		if(no)continue;
		rep(i,3){
			rep(j,s[i].size()){
				x[i]*=10;
				x[i]+=used[s[i][j]-'a'];
			}
		}
		if(x[0]+x[1]==x[2]){
			rep(i,3){
				cout<<x[i]<<"\n";
			}
			return;
		}
	}while(next_permutation(all(v)));
	ng();
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
