#include <iostream>

using namespace std;

int main () {
	string str1, str2;
	while (getline(cin, str1)){
		if (str1 == "#"){
			break; 
		}
		getline(cin, str2);
		for (int i = 0; i < str1.size(); i++){
			int k = 0; //更新k为0 
			for (int j = 0; j < str2.size(); j++){
				if (str1[i] == str2[j]){
					k++;
				}
			}
			cout << str1[i] << " " << k << endl;
		}
	}
	return 0;
}