/*
	© MATTO MATTI 2016
	http://mattomatti.com/pl/a35
	napisane przy użyciu Visual Studio Community 2015
	2016-02-15 v 1.0
*/

#include <iostream>

using namespace std;

const int key_length = 'Z' - 'A' + 1;

void changeTxt(char* text, char* code){
	for(int i = 0; text[i]; i++)
		if(text[i] >= 'A' && text[i] <= 'Z')
			text[i] = code[text[i] - 'A'];
}

int main () {
	char* text = new char[128];
	char* keyword = new char[128];
	char* key = new char[key_length];

	cin.getline(text,128);
	cin.getline(keyword,128);
	key[key_length - 1] = '\0';

	int key_i = 0;
	for(int i = 0; keyword[i]; i++){
		bool dodaj = true;
		if(keyword[i] >= 'A' && keyword[i] <= 'Z'){
			for(int j = 0; j < key_i; j++){
				if(key[j] == keyword[i]){
					dodaj = false;
				}
			}
			if(dodaj){
				key[key_i++] = keyword[i];
			}
		}
	}

	for(int i = 0; i < key_length; i++){
		bool dodaj = true;
		for(int j = 0; j < key_i; j++){
			if(key[j] == 'A' + i){
				dodaj = false;
			}
		}
		if(dodaj){
			key[key_i++] = 'A' + i;
		}
	}

	changeTxt(text, key);
	cout << text << endl;
	
	char* key_d = new char[key_length];
	for(int i = 0; i < key_length; i++){
		key_d[key[i] - 'A'] = 'A' + i;
	}

	changeTxt(text, key_d);
	cout << text << endl;
	delete[] text, keyword, key, key_d;
	system("pause");
	return 0;
}