#include <iostream>
using namespace std;

int main() {
    string s1,s2;
    while(getline(cin,s1)){
        if(s1 == "#")return 0;
        int arr[200];
        for(int i =0;i<200;i++)arr[i] = -1;
        getline(cin,s2);
        for(int i = 0;i<s1.length();i++){
            arr[s1[i]] = 0;
            for(int j = 0;j<s2.length();j++){
                if(s2[j] == s1[i])arr[s1[i]]++;
            }
        }
        //输出数组
        for(int i = 0;i<s1.length();i++){
            cout<<s1[i]<<" "<<arr[s1[i]]<<endl;
        }
    }
}
// 64 位输出请用 printf("%lld")