#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main() {
  string line;
  while (getline(cin, line)) {
    stringstream stream;
    stream << line;
    string command, tree1, tree2;
    stream >> command >> tree1 >>  tree2;
    //cout << command << tree1 << tree2;
    //cout << tree1[0] << endl;

    int open = 0;
    int index1 = 0, index2 = 0;
    while (index1 < tree1.length() && index2 < tree2.length()) {
      if (tree1[index1] == tree2[index2]) { //if same characters
	cout << tree1[index1];
	index1++;
	index2++;
      } else  { //if different characters
	if (tree1[index1] == '(') {
	  open++;
	  index1++;
	  if (command == "u") cout << "(";
	  while (open != 0) {
	    if (tree1[index1] == '(') open++;
	    if (tree1[index1] == ')') open--;
	    if (command == "u") cout << tree1[index1];
	    index1++;
	   
	  }
	} else if (tree2[index2] == '(') {
	  open++;
	  index2++;
	  if (command == "u") cout << "(";
	  while (open != 0) {
	    if (tree2[index2] == '(') open++;
	    if (tree2[index2] == ')') open--;
	    if (command == "u") cout << tree2[index2];
	    index2++;
	    
	  }
	}
      }
     }
     cout << endl;
  }
}