form =input()
n =int(input())defjudge(str3):
flag =Truefor k in str3:ifnot(k.islower()or k.isdigit()or i =='-'):
flag =Falsebreakreturn flag
for j inrange(n):
dict1 ={}
data =input().split()print("Case "+str(j +1)+": ", end="")
index =1while index <len(data):
i = data[index]if i[0]=='-'and i[1]in form andlen(i)==2and i[1]!=':':# 选项 仅以-开头有可能是选项也有可能是参数try:if form[form.index(i[1])+1]==':':# 有参数ifnot judge(data[index +1]):break
dict1[i]=" "+ data[index +1]
index +=2else:# 无参数
dict1[i]=""
index +=1except IndexError:# 最后一个 无参数
dict1[i]=""
index +=1else:break
info =sorted(dict1.items(), key=lambda i: i[0])for i in info:print(i[0]+ i[1], end=" ")print()