#include <iostream>
using namespace std;

int main() {
    string s1, s2;
    while (getline(cin, s1) && s1 != "#") { // 注意 while 处理多个 case
        getline(cin, s2);
        for(int i = 0; i <s1.length(); i ++){
            int cnt = 0;
            for(int j = 0; j < s2.length(); j ++){
                if (s1[i] == s2[j])
                    cnt ++;
            }
            cout << s1[i] << " " << cnt << endl;
        }
    }

    return 0;
}
// 64 位输出请用 printf("%lld")