#include <cstdlib>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
string s;
string *h, *t;
int *b;
int n;
vector<string> p;
int step=0;
int op;
int f()
{
for( int i=0 ; i<n ; i++ ) // i -- проход команд (h)
if( h[i] == "" )
{
s = t[i]+s;
return b[i];
}
else for( int j=0 ; j<(int)s.length() ; j++ ) // j -- поиск нужной команды в строке (s)
if( h[i][0] == s[j] )
{
//Проверка слова на идентичность
int r=0;
for( int k=0 ; k<(int)h[i].length() ; k++ )
{
if( h[i][k] == s[j+k] )
{
r++;
}
}
if( r == h[i].length() )
{
// Замена
string s1="", s2="";
for( int i1=0 ; i1<j ; i1++ )
{
s1 += s[i1];
}
for( int i1 = j + h[i].length() ; i1<s.length() ; i1++ )
{
s2 += s[i1];
}
s = s1 + t[i] + s2;
step++;
//if(op)cout << "Step#" << step << ": " << s << endl;
return b[i];
}
}
return 0;
}
int main()
{
string sm;
//------------------------------------------
cin >> s;
while( cin>>sm )
{
p.push_back(sm);
}
//cout << "Показывать пошаговые действия?(1\\0)\n";
//cin >> op;
//op = (op?1:0); // небольшой фильтр
n = p.size();
h=new string[n];
t=new string[n];
b=new int[n];
for( int i=0 ; i<n ; i++ )
{
int j;
for( j=0 ; !(p[i][j]=='=' && p[i][j+1]=='>') && !(p[i][j]=='-' && p[i][j+1]=='>') ; j++ );
t[i]=h[i]="";
for( int k=0 ; k<j ; k++ ) h[i]+=p[i][k];
b[i]=(p[i][j]=='='?0:1);
for( int k=j+2 ; k<p[i].size() ; k++ ) t[i]+=p[i][k];
}
for( ; f() ; );
cout << s << endl;
}
I2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDx2ZWN0b3I+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKCnN0cmluZyBzOwpzdHJpbmcgKmgsICp0OwppbnQgKmI7CmludCBuOwp2ZWN0b3I8c3RyaW5nPiBwOwppbnQ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