#include #include #include #include namespace rklib { template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template bool chmin_non_negative(T &a, const T &b) { if (a < 0 || a > b) { a = b; return true; } return false; } template T div_floor(T a, T b) { if (b < 0) a *= -1, b *= -1; return a >= 0 ? a / b : (a + 1) / b - 1; } template T div_ceil(T a, T b) { if (b < 0) a *= -1, b *= -1; return a > 0 ? (a - 1) / b + 1 : a / b; } } // namespace rklib #define For(i, a, b) for (int i = (int)(a); (i) < (int)(b); ++(i)) #define rFor(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); --(i)) #define rep(i, n) For(i, 0, n) #define rrep(i, n) rFor(i, n, 0) #define fi first #define se second using namespace std; using namespace rklib; using lint = long long; using pii = pair; using pll = pair; int main() { string s; cin >> s; int d[26][26]; rep(i, 26) rep(j, 26) cin >> d[i][j]; bool ans[26][26]; rep(i, 26) rep(j, 26) ans[i][j] = true; int prv[26]; fill(prv, prv + 26, -1); rep(i, s.size()) { rep(c, 26) if (prv[c] >= 0) { if (prv[c] + d[c][s[i] - 'a'] > i) { ans[c][s[i] - 'a'] = false; } } prv[s[i] - 'a'] = i; } rep(i, 26) { rep(j, 26) printf("%c ", ans[i][j] ? 'Y' : 'N'); puts(""); } }