#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); string S; cin >> S; int N = S.size(), K = 26; vector> D(K, vector(K)); rep(i,K) rep(j,K) cin >> D[i][j]; vector> ans(K, vector(K, 1)); vector> L(K), R(K); rep(i,N) R[S[i] - 'a'].push_back(i); rep(c,K) reverse(R[c].begin(), R[c].end()); rep(i,N) { R[S[i] - 'a'].pop_back(); rep(a,K) if(!L[a].empty()) { int b = S[i] - 'a'; ans[a][b] &= L[a].back() + D[a][b] <= i; } rep(b,K) if(!R[b].empty()) { int a = S[i] - 'a'; ans[a][b] &= i + D[a][b] <= R[b].back(); } L[S[i] - 'a'].push_back(i); } rep(i,K) { rep(j,K) cout << (ans[i][j] ? "Y" : "N") << " \n"[j == K - 1]; } }