#include <deque>
#include <iostream>
#include <set>
#include <string>
using namespace std;
/*
程序思路:目标是构建两个一一对应的字符串
一个是 26位字母表
一个是 输入中的字符串按照题目要求的方法得出的字符串 str2.
题目的关键也是构建 str2.
如何构建str2?
1. 遍历字符串
2. 通过set集合去除字符串中重复元素
3. 通过deque 双端队列保持字母的相对位置不变
4. 这样就将单词中包含有重复的字母,只保留第1个,将所得结果作为新字母表开头,
5. 之后再补上后面缺少的单词
*/
int main() {
string key, str;
cin >> key;
cin >> str;
string str1 = "abcdefghijklmnopqrstuvwxyz";
string str2;
int len = key.length();
deque<char> dq;
set<char> st;
for (auto c : key) {
if (st.count(c) ) {
continue;
}
st.insert(c);
dq.push_back(c);
}
while (!dq.empty()) {
str2 += dq.front();
dq.pop_front();
}
for (char c = 'a'; c <= 'z'; c++) {
if (st.count(c) ) {
continue;
}
str2 += c;
}
string ans;
for (auto c : str) {
ans += str2[str1.find_last_of(c)];
}
cout << ans << endl;
}
// 64 位输出请用 printf("%lld")