INF = 1 << 30 s = list(input()) d = [list(map(int, input().split())) for _ in range(26)] n = len(s) for i in range(n): s[i] = ord(s[i]) - ord("a") dp = [[INF for _ in range(26)] for _ in range(n)] dp[n - 1][s[n - 1]] = n - 1 diff = [[INF for _ in range(26)] for _ in range(26)] for i in range(n - 2, -1, -1): for c in range(26): dp[i][c] = dp[i + 1][c] for c in range(26): diff[s[i]][c] = min(diff[s[i]][c], dp[i][c] - i) dp[i][s[i]] = i for i in range(26): row = ["Y" for _ in range(26)] for j in range(26): if d[i][j] > diff[i][j]: row[j] = "N" print(*row, sep=" ")