rle = gets.split[0..-2]
word = gets.split[0..-2]
alter = gets.split[0..-2]

idx = nil
(0..(rle.size-word.size)/2).each do |k|
    catch(:break) do
        i = 2 * k
        throw(:break) unless rle[i] == word[0]
        throw(:break) unless rle[i+1].to_i >= word[1].to_i
        (2..word.size-2).each do |j|
            throw(:break) unless rle[i+j] == word[j]
        end
        if rle[i+word.size-1].to_i >= word[-1].to_i
            idx = k
        end
    end
    break if idx
end

if !idx
    puts rle * ' ' + " $"
    exit
end

a = (idx == 0 ? [] : rle[0..2*idx-1])
b = alter
b = [word[0], rle[2*idx+1].to_i - word[1].to_i] + b if rle[2*idx+1].to_i > word[1].to_i
b += [word[-2], rle[2*idx+word.size-1].to_i - word[-1].to_i] if rle[2*idx+word.size-1].to_i > word[-1].to_i
c = rle[2*idx+word.size..-1]

x = a + b + c
y = []

x.each_slice(2) do |c, k|
    k = k.to_i
    if c == y[-2]
        y[-1] += k
    else
        y += [c, k]
    end
end

puts y * ' ' + " $"