#include <cstdio>
#include <iostream>
#include <string>

using namespace std;


int main() {
    string s1,s2;
    while(getline(cin,s1)){
        if(s1[0]=='#'){
            break;
        }
        getline(cin,s2);
        int len1=s1.size();
        int len2=s2.size();
        for(int i=0;i<len1;i++){
            int times=0;
            for(int j=0;j<len2;j++){
                if(s2[j]==s1[i]){
                    times++;
                }
            }
            printf("%c %d\n",s1[i],times);
        }
    }

    return 0;
}