#include <stdio.h>
int Length(char a[])
{
    int n = 0;
    for (int i = 0; a[i] != '\0'; i++)
    {
        n++;
    }
    return n;
}
int main() {
    char a[5] = "";
    char b[80] = "";
    while (gets(a)){
        if(a[0]=='#')
        {
            break;
        }
        gets(b);
        int n = Length(a);
        int m = Length(b);
        for (int i = 0; i < n; i++) {
            int count = 0;
            for (int j = 0; j < m; j++) {
                if (a[i] == b[j]) {
                    count++;
                }
            }
            printf("%c %d\n", a[i], count);
        }
    }
    return 0;
}