import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); char[] inputs = sc.next().toCharArray(); int[] starts = new int[26]; Arrays.fill(starts, -1); int[][] matrix = new int[26][26]; for (int[] arr : matrix) { Arrays.fill(arr, Integer.MAX_VALUE); } for (int i = 0; i < inputs.length; i++) { int idx = inputs[i] - 'a'; for (int j = 0; j < 26; j++) { if (starts[j] >= 0) { matrix[j][idx] = Math.min(matrix[j][idx], i - starts[j]); } } starts[idx] = i; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < 26; i++) { for (int j = 0; j < 26; j++) { if (j > 0) { sb.append(" "); } sb.append(matrix[i][j] >= sc.nextInt() ? "Y" : "N"); } sb.append("\n"); } System.out.print(sb); } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }