s=input().split(';')
name=['A1','A2','A3','A4','A5','A6']
cos=[2,3,4,5,8,6]
val=[1,2,5,10]
balance=0
def c(mon_mach_f,balance_f):
    for a1 in range(int(mon_mach_f[0])+1):
        for b1 in range(int(mon_mach_f[1])+1):
            for c1 in range(int(mon_mach_f[2])+1):
                for d1 in range(int(mon_mach_f[3])+1):
                    if a1+2*b1+5*c1+10*d1==balance_f:
                        balance_f=0
                        mon_mach_f[0]-=a1 
                        mon_mach_f[1]-=b1
                        mon_mach_f[2]-=c1
                        mon_mach_f[3]-=d1
                        return mon_mach_f,balance_f,a1,b1,c1,d1
                    else:
                        return False
                        #c(mon_mach_f,balance_f-1)  
for i in s[:len(s)-1]:
    l=i[0]
    if l=='r':
        a=i.split()
        num=list(map(int,a[1].split('-')))
        mon_mach=list(map(int,a[2].split('-')))
        print('S001:Initialization is successful')
    elif l=='p':
        mon_in=int(i.split()[1])
        if mon_in not in val:
            print('E002:Denomination error')
        elif mon_in>mon_mach[0]+2*mon_mach[1]:
            print('E003:Change is not enough, pay fail')
        elif sorted(num)[-1]==0:
            print('E005:All the goods sold out')
        else:
            mon_mach[val.index(mon_in)]+=1
            balance+=mon_in
            print('S002:Pay success,balance='+str(balance))
    elif l=='b':
        a=i.split()[1]
        if a not in name:
            print('E006:Goods does not exist')
        elif num[name.index(a)]=='0':
            print('E007:The goods sold out')
        elif cos[name.index(a)]>balance:
            print('E008:Lack of balance')
        else:
            balance-=cos[name.index(a)]
            num[name.index(a)]-=1
            print('S003:Buy success,balance='+str(balance))
    elif l=='c':
        if balance==0:
            print('E009:Work failure')
        else:
            if balance>=mon_mach[0]+2*mon_mach[1]+5*mon_mach[2]+10*mon_mach[3]:
                for j in range(4):
                    print(str(val[j])+' yuan coin number='+str(mon_mach[j]))
            else:
                ls=[]
                for a in range(mon_mach[0]+1):
                    for b in range(mon_mach[1]+1):
                        for c in range(mon_mach[2]+1):
                            for d in range(mon_mach[3]+1):
                                if a+2*b+5*c+10*d==balance:
                                    ls.append([a,b,c,d])
                if ls==[]:
                    lss=[]
                    for j in range(balance,1,-1):
                        for a in range(mon_mach[0]+1):
                            for b in range(mon_mach[1]+1):
                                for c in range(mon_mach[2]+1):
                                    for d in range(mon_mach[3]+1):
                                        if a+2*b+5*c+10*d==j:
                                            ls.append([a,b,c,d])
                                            lss.append(j)
                    for j in ls:
                        if sum(j)!=max(j):
                            ls.remove(j)
                #print(ls)                            
                ls=sorted(ls,key=lambda x:sum(x))
                #print(ls)                            
                balance=0
                mon_mach[0]-=ls[0][0]
                mon_mach[1]-=ls[0][1]
                mon_mach[2]-=ls[0][2]
                mon_mach[3]-=ls[0][3]
                print('1 yuan coin number='+str(ls[0][0]))
                print('2 yuan coin number='+str(ls[0][1]))
                print('5 yuan coin number='+str(ls[0][2]))
                print('10 yuan coin number='+str(ls[0][3]))

    elif l=='q' and len(i)==3:
        a=i[2]
        if a=='0':
            dic={}
            for i in range(6):
                dic[name[i]]=num[i]
            d=sorted(dic.items(),key=lambda x:x[1],reverse=True)
            for j in d:
                print(str(j[0])+' '+str(cos[name.index(j[0])])+' '+str(j[1]))
        elif a=='1':
            for j in range(4):
                print(str(val[j])+' yuan coin number='+str(mon_mach[j]))
        else:
            print('E010:Parameter error')
    elif l=='q':
        print('E010:Parameter error')