from bisect import bisect_left import sys input = sys.stdin.readline def iinput(): return int(input()) def sinput(): return input().rstrip() def i0input(): return int(input()) - 1 def linput(): return list(input().split()) def liinput(): return list(map(int, input().split())) def miinput(): return map(int, input().split()) def li0input(): return list(map(lambda x: int(x) - 1, input().split())) def mi0input(): return map(lambda x: int(x) - 1, input().split()) INF = 10**20 MOD = 1000000007 S = sinput() D = [] for _ in [0] * 26: D.append(liinput()) ans = [['Y' for _ in [0] * 26] for _ in [0] * 26] idx = [[] for _ in [0] * 26] alpha = 'abcdefghijklmnopqrstuvwxyz' a_to_i = {a: i for i, a in enumerate(alpha)} for i, c in enumerate(S): idx[a_to_i[c]].append(i) for i in range(26): if idx[i]: for j, k in zip(idx[i], idx[i][1:]): if k - j < D[i][i]: ans[i][i] = 'N' break for a in range(26): for b in range(26): if a == b: continue if idx[a] and idx[b]: for i in idx[a]: x = bisect_left(idx[b], i) try: j = idx[b][x] if j - i < D[a][b]: ans[a][b] = 'N' break except IndexError: continue for a in ans: print(*a)