#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
short Lwidth, Lheight;
cin >> Lwidth >> Lheight; cin.ignore();
string Text;
char **alphabet = new char*[256];
//initializing alphabet
for (char ltr = 'a'; ltr < 'z'+1; ++ltr)
{
alphabet[ltr] = new char[Lwidth];
}
for (char ltr = 'A'; ltr < 'Z'+1; ++ltr)
{
alphabet[ltr] = new char[Lwidth];
}
alphabet['?'] = new char[Lwidth];
getline(cin, Text);
for (short h = 0; h < Lheight; ++h)
{
char ltr;
for (ltr = 'a'; ltr < 'z'+1; ++ltr) //reading letters
{
for (short w = 0; w < Lwidth; ++w)
{
scanf("%c", &alphabet[ltr][w]);
alphabet[ltr-('a'-'A')][w] = alphabet[ltr][w];
}
}
for (short w = 0; w < Lwidth; ++w) //reading ?
{
scanf("%c", &alphabet['?'][w]);
}
scanf("%c", <r); //reading endl
if (ltr != '\n') cerr << "ERROR: INVALID TESTS PROVIDED\n";
//Putting result out.
for (short i = 0; i < Text.size(); ++i)
{
if //it is a letter
(
(('a'-1 < Text[i]) && (Text[i] < 'z'+1)) ||
(('A'-1 < Text[i]) && (Text[i] < 'Z'+1))
) //then print it
cout << alphabet[Text[i]];
else //it is definitely something weird
cout << alphabet['?'];
}
cout << '\n';
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKQp7CiAgICBzaG9ydCBMd2lkdGgsIExoZWlnaHQ7CiAgICBjaW4gPj4gTHdpZHRoID4+IExoZWlnaHQ7IGNpbi5pZ25vcmUoKTsKICAgIHN0cmluZyBUZXh0OwogICAgY2hhciAqKmFscGhhYmV0ID0gbmV3IGNoYXIqWzI1Nl07CiAgICAKICAgIC8vaW5pdGlhbGl6aW5nIGFscGhhYmV0CiAgICBmb3IgKGNoYXIgbHRyID0gJ2EnOyBsdHIgPCAneicrMTsgKytsdHIpCiAgICB7CiAgICAgICAgYWxwaGFiZXRbbHRyXSA9IG5ldyBjaGFyW0x3aWR0aF07CiAgICB9CiAgICBmb3IgKGNoYXIgbHRyID0gJ0EnOyBsdHIgPCAnWicrMTsgKytsdHIpCiAgICB7CiAgICAgICAgYWxwaGFiZXRbbHRyXSA9IG5ldyBjaGFyW0x3aWR0aF07CiAgICB9CiAgICBhbHBoYWJldFsnPyddID0gbmV3IGNoYXJbTHdpZHRoXTsKICAgIAogICAgZ2V0bGluZShjaW4sIFRleHQpOwogICAgZm9yIChzaG9ydCBoID0gMDsgaCA8IExoZWlnaHQ7ICsraCkKICAgIHsKICAgICAgICBjaGFyIGx0cjsKICAgICAgICBmb3IgKGx0ciA9ICdhJzsgbHRyIDwgJ3onKzE7ICsrbHRyKSAvL3JlYWRpbmcgbGV0dGVycwogICAgICAgIHsKICAgICAgICAgICAgZm9yIChzaG9ydCB3ID0gMDsgdyA8IEx3aWR0aDsgKyt3KQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBzY2FuZigiJWMiLCAmYWxwaGFiZXRbbHRyXVt3XSk7CiAgICAgICAgICAgICAgICBhbHBoYWJldFtsdHItKCdhJy0nQScpXVt3XSA9IGFscGhhYmV0W2x0cl1bd107CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgCiAgICAgICAgZm9yIChzaG9ydCB3ID0gMDsgdyA8IEx3aWR0aDsgKyt3KSAvL3JlYWRpbmcgPwogICAgICAgIHsKICAgICAgICAgICAgc2NhbmYoIiVjIiwgJmFscGhhYmV0Wyc/J11bd10pOwogICAgICAgIH0KICAgICAgICAKICAgICAgICBzY2FuZigiJWMiLCAmbHRyKTsgLy9yZWFkaW5nIGVuZGwKICAgICAgICBpZiAobHRyICE9ICdcbicpIGNlcnIgPDwgIkVSUk9SOiBJTlZBTElEIFRFU1RTIFBST1ZJREVEXG4iOwogICAgICAgIAogICAgICAgIC8vUHV0dGluZyByZXN1bHQgb3V0LgogICAgICAgIGZvciAoc2hvcnQgaSA9IDA7IGkgPCBUZXh0LnNpemUoKTsgKytpKQogICAgICAgIHsKICAgICAgICAgICAgaWYgLy9pdCBpcyBhIGxldHRlcgogICAgICAgICAgICAoCiAgICAgICAgICAgICAgICAoKCdhJy0xIDwgVGV4dFtpXSkgJiYgKFRleHRbaV0gPCAneicrMSkpIHx8CiAgICAgICAgICAgICAgICAoKCdBJy0xIDwgVGV4dFtpXSkgJiYgKFRleHRbaV0gPCAnWicrMSkpCiAgICAgICAgICAgICkgLy90aGVuIHByaW50IGl0CiAgICAgICAgICAgICAgICBjb3V0IDw8IGFscGhhYmV0W1RleHRbaV1dOwogICAgICAgICAgICBlbHNlIC8vaXQgaXMgZGVmaW5pdGVseSBzb21ldGhpbmcgd2VpcmQKICAgICAgICAgICAgICAgIGNvdXQgPDwgYWxwaGFiZXRbJz8nXTsKICAgICAgICB9CiAgICAgICAgY291dCA8PCAnXG4nOwogICAgfQp9