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));
        }

        if (t == "i") {
            void dfs(in Node p, in Node q, ref Node r) {
                if (p.left !is null && q.left !is null) {
                    r.left = new Node;
                    dfs(p.left, q.left, r.left);
                }
                if (p.right !is null && q.right !is null) {
                    r.right = new Node;
                    dfs(p.right, q.right, r.right);
                }
            }
            Node z = new Node;
            dfs(x, 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 {
                    r.left = new Node;
                    dfs1( (p is null ? null : p.left), 
                          (q is null ? null : q.left), r.left );
                }
                if ( (p is null || p.right is null) && 
                     (q is null || q.right is null) ) {
                    r.right = null;
                } else {
                    r.right = new Node;
                    dfs1( (p is null ? null : p.right), 
                          (q is null ? null : q.right), r.right );
                }
            }
            Node z = new Node;
            dfs1(x, y, z);
            writeln(z);
        }

    }

    while (input) solve;
}

Measured memory_bytes: 1144