def find_mid(str)
  tmp = 0
  len = str.length
  for i in (0...len)
    tmp += 1 if str[i] == '('
    tmp -= 1 if str[i] == ')'
    return i if str[i] == ',' and tmp == 1
  end
end

class Node
  def initialize
    @left_son = nil
    @right_son = nil
  end

  def extend(str)
    len = str.length
    mid = find_mid(str)
    if mid > 1
      @left_son = Node.new unless @left_son
      @left_son.extend(str[1...mid])
    end
    if mid < len - 2
      @right_son = Node.new unless @right_son
      @right_son.extend(str[mid+1...len-1])
    end
  end

  def shrink(str)
    len = str.length
    mid = find_mid(str)
    if @left_son
      if mid > 1
        @left_son.shrink(str[1...mid])
      else
        @left_son = nil
      end
    end
    if @right_son
      if mid < len - 2
        @right_son.shrink(str[mid+1...len-1])
      else
        @right_son = nil
      end
    end
  end

  def to_s
    str = "("
    str += @left_son.to_s if @left_son
    str += ","
    str += @right_son.to_s if @right_son
    str += ")"
    return str
  end
end

while line = gets
  k, a, b = line.split()
  root = Node.new
  root.extend(a)
  root.extend(b) if k == "u"
  root.shrink(b) if k == "i"
  puts root.to_s
end