The evil Dr. Nope has planted a time bomb in the middle of the city, set to explode in exactly three hours!
Fortunately, Agent Double-O-Zero has gotten his hands on the bomb's deactivation code. Unfortunately, it's encrypted. Fortunately, Double-O-Zero has also gotten his hands on Dr. Nope's diary, which explains his encryption method in great detail!
The deactivation code is a string consisting of digits from to . Inside Dr. Nope's diary is a list of strings numbered to , the encryption keys. Each key is a permutation of the digits from to .
To encrypt the deactivation code, the digits of the code are numbered from to from left to right. Let be the -th digit of the unencrypted code and be the -th digit of the encrypted code. Dr. Nope sets to be equal to , and for every after that, he sets to be the digit at the -th position of the -th encryption key.
Can you help Double-O-Zero decrypt the code before it's too late?
Input Specification
The first lines each contain one permutation of the digits, the encryption keys.
The final line contains one string of digits, the encrypted deactivation code.
Output Specification
One string of digits, the decrypted deactivation code.
Sample Input
1234567890
2345678901
3456789012
4567890123
5678901234
6789012345
7890123456
8901234567
9012345678
0123456789
4780
Sample Output
4254
Explanation for Sample
To encrypt 4254
, the 4
stays the same. The 2
becomes the digit at the 2nd position of the 4th key, 7
. The 5
becomes the digit at the 5th position of the 2nd key, 8
. Finally, the 4
becomes the digit at the 4th position of the 5th key, 0
. 4254
is the only value that becomes 4780
when encrypted.
Comments