#include using namespace std; #include using namespace atcoder; #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) #define P pair #define LP pair #define fi first #define se second #define pb push_back #define eb emplace_back #define all(s) s.begin(), s.end() #define rall(s) s.rbegin(), s.rend() template void chmax(T& a, T b) { a = max(a, b); }; template void chmin(T& a, T b) { a = min(a, b); }; int main() { string s; cin >> s; vector d(26, vector(26)); rep(i,26)rep(j,26) cin >> d[i][j]; vector pos[26]; rep(i,s.size()) { pos[s[i]-'a'].pb(i); } const int INF = 1001001001; vector dmin(26,vector(26, INF)); rep(i,26)rep(j,26) { if (i == j) { rep(k,(int)pos[i].size()-1) { chmin(dmin[i][i], pos[i][k+1]-pos[i][k]); } } else { for (auto x : pos[i]) { auto it = lower_bound(all(pos[j]), x); if (it != pos[j].end()) chmin(dmin[i][j], abs(x-*it)); } } } rep(i,26){ rep(j,26) { if (d[i][j] <= dmin[i][j]) cout << "Y" << " "; else cout << "N" << " "; } cout << endl; } return 0; }