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 ~1 \le N \le 1\,000\,000~ digits from ~0~ to ~9~. Inside Dr. Nope's diary is a list of ~10~ strings numbered ~0~ to ~9~, the encryption keys. Each key is a permutation of the digits from ~0~ to ~9~.
To encrypt the deactivation code, the digits of the code are numbered from ~0~ to ~N - 1~ from left to right. Let ~d[i]~ be the ~i~-th digit of the unencrypted code and ~e[i]~ be the ~i~-th digit of the encrypted code. Dr. Nope sets ~e~ to be equal to ~d~, and for every ~1 \le i \le N - 1~ after that, he sets ~e[i]~ to be the digit at the ~d[i]~-th position of the ~d[i - 1]~-th encryption key.
Can you help Double-O-Zero decrypt the code before it's too late?
The first ~10~ lines each contain one permutation of the ~10~ digits, the ~10~ encryption keys.
The final line contains one string of ~N~ digits, the encrypted deactivation code.
One string of ~N~ digits, the decrypted deactivation code.
1234567890 2345678901 3456789012 4567890123 5678901234 6789012345 7890123456 8901234567 9012345678 0123456789 4780
Explanation for Sample
4 stays the same. The
2 becomes the digit at the 2nd position of the 4th key,
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,
4254 is the only value that becomes
4780 when encrypted.