def conv(str)
    eval(?[ + str.gsub(?[, '').gsub(?], ?,).gsub(?(, ?[).gsub(?), '],') + ?])
end

def merge(a, b)
    return [] if a.empty? or b.empty?
    [merge(a[0], b[0]), a[1] + b[1], merge(a[2], b[2])]
end

def inv(a)
    return '()' if a.empty?
    "(#{inv(a[0])}[#{a[1]}]#{inv(a[2])})"
end

a = conv(gets.chomp)
b = conv(gets.chomp)

puts inv(merge(a, b))[1..-2]