#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <list>
#include <iomanip>
#include <set>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
const int MOD=1000000007;
const int INF=1000000000;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
char op;
string s1,s2;
struct Tree
{
  vector<Tree> left,right;
};
Tree null;

class Parser{
public:

  Tree parsetree(State &begin)
  {
    Tree ret;
    if(*begin=='(') begin++;
    if(*begin!=',')
      {
	//begin++;
	ret.left.push_back(parsetree(begin));
      }
    if(*begin==',')begin++;
    if(*begin!=')')
      {
	//begin++;
	ret.right.push_back(parsetree(begin));
      }
    if(*begin==')') begin++;
    return ret;
  }
  string dfs_i(Tree t1,Tree t2)
  {
    string ret=",";
    if(t1.left.size()!=0 && t2.left.size()!=0)
      {
	ret="("+dfs_i(t1.left[0],t2.left[0])+ret;
      }
    else ret="(" + ret;
    if(t1.right.size()!=0 && t2.right.size()!=0)
      {
	ret=ret+dfs_i(t1.right[0],t2.right[0])+")";
      }
    else ret=ret+")";
    return ret;
  }
  string dfs_u(Tree t1,Tree t2)
  {
    string ret=",";
    Tree tmp1,tmp2;
    if(t1.left.size()!=0 || t2.left.size()!=0)
      {
	tmp1=(t1.left.size()!=0) ? t1.left[0]:null;
	tmp2=(t2.left.size()!=0) ? t2.left[0]:null;
	ret="("+dfs_u(tmp1,tmp2)+ret;
      }
    else ret="(" + ret;
    if(t1.right.size()!=0 || t2.right.size()!=0)
      {
	tmp1=(t1.right.size()!=0) ? t1.right[0]:null;
	tmp2=(t2.right.size()!=0) ? t2.right[0]:null;
	ret=ret+dfs_u(tmp1,tmp2)+")";
      }
    else ret=ret+")";
    return ret;
  }
  /*
  ll number(State &begin)
  {
    ll ret=0;
    while(isdigit(*begin))
      {
	ret*=10;
	ret+=(*begin-'0');
	begin++;
      }
    return ret;
  }

  ll expression(State &begin)
  {
    ll ret=term(begin);
    for(;;)
      {
	if(*begin=='+')
	  {
	    begin++;
	    ret=(ret+term(begin))%p;
	  }
	else if(*begin=='-')
	  {
	    begin++;
	    ret=(ret+(p-term(begin)))%p;
	  }
	else
	  {
	    break;
	  }
      }
    return ret%p;
  }

  ll term(State &begin)
  {
    ll ret=factor(begin);
    for(;;)
      {
	if(*begin=='*')
	  {
	    begin++;
	    ret=(ret*factor(begin))%p;
	  }
	else if(*begin=='/')
	  {
	    begin++;
	    State tmp=begin;
	    if(factor(tmp)==0)
	      {
		zerodiv=true;
		return 0;
	      }
	    ret=(ret*(ppow(factor(begin),p-2,p)))%p;
	  }
	else
	  {
	    break;
	  }
      }
    return ret;
  }

  ll factor(State &begin)
  {
    ll ret;
    if(*begin=='(')
      {
	begin++;
        ret=expression(begin);
	begin++;
	return ret;
      }
    else
      {
	ret=number(begin)%p;
      }
      return ret;
      }*/
};


int main(int argc,char const* argv[])
{
  while(cin >> op)
    {
      Parser ps;
      cin >> s1 >> s2;
      State begin1=s1.begin();
      State begin2=s2.begin();
      Tree t1=ps.parsetree(begin1);
      Tree t2=ps.parsetree(begin2);
      string ans="";
      if(op=='i')
	{
	  ans=ps.dfs_i(t1,t2);
	}
      if(op=='u')
	{
	  ans=ps.dfs_u(t1,t2);
	}
      cout << ans << endl;
    }
  return 0;
}



Measured memory_bytes: 3132