s=input() n=26 D=[list(map(int,input().split())) for i in range(n)] dat=[-1]*n ans=[["Y"]*n for i 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 i in ans: print(*i)