S = input() n = 26 D = [list(map(int,input().split())) for _ in range(n)] dat = [-1] * n ans = [['Y'] * n for _ in range(n)] for i in range(len(S)): c = ord(S[i]) - ord('a') for cc in range(n): if dat[cc] == -1:continue if dat[cc] + D[cc][c] > i: ans[cc][c] = 'N' dat[c] = i for l in ans: print(*l)