d, m = map(int, input().split(' '))
h = {}
for _ in range(d):
    s = input()
    h[(s[0], s[-1], len(s), ''.join(sorted(s[1: -1])))] = s
for k, v in h.items():
    print(k, v)
print("#" * 20)
while 1:
    try:
        words = input().split(' ')
        line = []
        for word in words:
            line.append(h.get((word[0], word[-1], len(word), ''.join(sorted(word[1:-1]))), ''))
        print(' '.join(line))
    except:
        break
    

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: