#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

const char *left(const char *p){
  if(p == NULL) return NULL;
  assert(*p == '(');

  if(*(p+1) == '(') return p+1;
  return NULL;
}

const char *right(const char *p){
  if(p == NULL) return NULL;
  assert(*p == '(');
  int depth = 0;
  p++;

  while(!(depth == 0 && *p == ',')){
    if(*p == '(') depth++;
    if(*p == ')') depth--;
    p++;
  }

  p++;
  if(*p == '(') return p;
  return NULL;
}

void solve(const char *p1, const char *p2, bool inter){
  if(p1 == NULL && p2 == NULL) return;

  const char *l1 = left(p1);
  const char *r1 = right(p1);
  const char *l2 = left(p2);
  const char *r2 = right(p2);

  printf("(");

  if(inter){
    if(l1 == NULL || l2 == NULL){
    }else{
      solve(l1,l2,inter);
    }
  }else{
    if(l1 == NULL && l2 == NULL){
    }else{
      solve(l1,l2,inter);
    }
  }

  printf(",");

  if(inter){
    if(r1 == NULL || r2 == NULL){
    }else{
      solve(r1,r2,inter);
    }
  }else{
    if(r1 == NULL && r2 == NULL){
    }else{
      solve(r1,r2,inter);
    }
  }

  printf(")");
}

int main(){
  string str;
  while(getline(cin, str)){
    stringstream ss(str);
    char w;
    string s1,s2;
    ss >> w >> s1 >> s2;

    solve(s1.c_str(), s2.c_str(), w == 'i');
    puts("");
  }
  return 0;
}