#include <iostream>
using namespace std;

void count(string s1,string s2) {
    int cnt;
    for(int i = 0;i < s1.length(); i++) {
        cnt = 0;
        for(int j = 0;j < s2.length(); j++) {
            if(s1[i] == s2[j]) {
                cnt++;
            }
        }
        cout << s1[i] << ' ' << cnt << endl;
    }

    return ;  
}

int main() {
    string s1, s2;
    while(getline(cin, s1)) {
        if(s1[0] == '#') break;
        getline(cin, s2);
        count(s1, s2);
    }
    return 0;
}