#include <cstdio>
#include <cassert>
#include <algorithm>
#include <vector>
#include <string>

void skip(const std::string &s, size_t &i, bool out) {
  if (s[i] == ',') return;
  assert(s[i] == '(');
  size_t opened=1;
  ++i;
  if (out) printf("(");

  while (opened) {
    if (s[i] == '(') ++opened;
    if (s[i] == ')') --opened;
    if (out) printf("%c", s[i]);
    ++i;
  }
}

void fourt(
    const std::string &s, size_t &i, const std::string &t, size_t &j, 
    char op) {

  assert(s[i] == '(' && t[j] == '(');
  ++i;
  ++j;
  printf("(");
  if (s[i] == ',' && t[j] == ',') {
  } else if (s[i] == ',') {
    skip(t, j, (op == 'u'));
  } else if (t[j] == ',') {
    skip(s, i, (op == 'u'));
  } else {
    fourt(s, i, t, j, op);
  }

  printf(",");
  assert(s[i] == ',' && t[j] == ',');
  ++i;
  ++j;
  if (s[i] == ')' && t[j] == ')') {
  } else if (s[i] == ')') {
    skip(t, j, (op == 'u'));
  } else if (t[j] == ')') {
    skip(s, i, (op == 'u'));
  } else {
    fourt(s, i, t, j, op);
  }

  printf(")");
  ++i;
  ++j;
}

int testcase_ends() {
  char op;
  if (scanf(" %c", &op) == EOF)
    return 1;

  char buf[384];
  scanf("%s", buf);
  std::string s=buf;
  scanf("%s", buf);
  std::string t=buf;

  size_t i=0, j=0;
  fourt(s, i, t, j, op);
  printf("\n");
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}

