import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

class Node {
    Node left, right;
    this(Node left = null, Node right = null) {
        this.left = left;
        this.right = right;
    }
    override string toString() {
        return "(" ~ (left is null ? "" : left.toString) ~ ","
                   ~ (right is null ? "" : right.toString) ~ ")";
    }
}
 
void main() {

    string t, a, b;

    bool input() {
        string s = readln;
        if (s is null) return false;
        auto _ = s.split(" ");
        t = _[0]; a = _[1]; b = _[2];
        return true;
    }

    void solve() {

        Node parse(string s) {
            int index = 0;
            Node node() {
                assert(s[index] == '(');
                index++;
                Node left, right;
                left = (s[index] == ',' ? null : node);
                assert(s[index] == ',');
                index++;
                right = (s[index] == ')' ? null : node);
                assert(s[index] == ')');
                index++;
                return new Node(left, right);
            }
            return node;
        }
        
        Node x = parse(a),
             y = parse(b);

        int height(Node node) {
            if (node is null) return 0;
            return max(height(node.right), height(node.left)) + 1;
        }

        Node buildCompleteTree(int h) {
            if (h == 0) return null;
            return new Node(buildCompleteTree(h - 1), buildCompleteTree(h - 1));
        }

        Node z = buildCompleteTree(max(height(x), height(y)));

        if (t == "i") {
            void dfs(in Node p, ref Node q) {
                if (p is null || q is null) return;
                if (p.left is null) q.left = null;
                if (p.right is null) q.right = null;
                dfs(p.left, q.left);
                dfs(p.right, q.right);
            }
            dfs(x, z);
            dfs(y, z);
            writeln(z);
        } else {
            assert(t == "u");
            void dfs1(in Node p, in Node q, ref Node r) {
                if ( (p is null || p.left is null) && 
                     (q is null || q.left is null) ) {
                    r.left = null;
                } else {
                    dfs1(p.left, q.left, r.left);
                }
                if ( (p is null || p.right is null) && 
                     (q is null || q.right is null) ) {
                    r.right = null;
                } else {
                    dfs1(p.right, q.right, r.right);
                }
            }
            dfs1(x, y, z);
            writeln(z);
        }

    }

    while (input) solve;
}