using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
class Solution
{
static void Main(string[] args)
{
int w = int.Parse(Console.ReadLine());
int h = int.Parse(Console.ReadLine());
string t = Console.ReadLine();
Dictionary<char, List<string>> ls = new Dictionary<char, List<string>>();
for(int y = 0; y < h; y++)
{
string ls_data = Console.ReadLine();
for(int x = 0; x < ls_data.Length; x += w)
{
char c = (char)(65 + x / w);
if(!ls.ContainsKey(c))
{
ls.Add(c, new List<string>());
}
ls[c].Add(ls_data.Substring(x, w));
}
}
for(int y = 0; y < h; y++)
{
string ln = string.Empty;
for(int i = 0; i < t.Length; i++)
{
char c = char.ToUpper(t[i]);
if(ls.ContainsKey(c))
{
ln += ls[c][y];
}
else
{
ln += ls.Last().Value[y];
}
}
Console.WriteLine(ln);
}
}
}