def str_match(s, t):
    res = {}
    # for i in range(len(t)):
    #     res[t[i]] = 0
    c = 0
    for i in t:
        c = 0
        for j in s:
            if j == i:
                c += 1
        print("{} {}".format(i, c))
    

while True:
    try:
        t = input()
        if t == '#':
            break
        s = input()
        str_match(s, t)
       
    except:
        break