while 42:
t = input()
if t == '#':
break
lst = t.split()
alpha_upper = lst[0].upper()
alpha_lower = lst[0].lower()
s = " ".join(lst[1:])
cnt = s.count(alpha_upper) + s.count(alpha_lower)
print("{0} {1}".format(alpha_lower, cnt))