#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; int D[26][26]; int A[26][26]; const int INF=1e9; int B[26]; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); string s; cin>>s; int n=s.size(); rep(i,26) rep(j,26){ cin>>D[i][j]; A[i][j]=INF; } rep(i,26) B[i]=-1; rep(i,n){ int a=s[i]-'a'; rep(j,26){ if(B[j]==-1) continue; A[j][a]=min(A[j][a],i-B[j]); } B[a]=i; } rep(i,26){ rep(j,26){ if(j) cout<<" "; if(D[i][j]<=A[i][j]) cout<<'Y'; else cout<<'N'; } cout<