fn main() { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s = s.trim().chars().map(|c| c as usize - 'a' as usize).collect::>(); let d = (0..26).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); temp }) .collect::>>(); let n = 26; let mut mins = vec![vec![]; n]; for i in 0..s.len() { mins[s[i]].push(i); } for i in 0..n { mins[i].reverse(); } let mut result = vec![vec![true; n]; n]; for i in 0..s.len() { mins[s[i]].pop().unwrap(); for j in 0..n { if mins[j].is_empty() { continue; } result[s[i]][j] &= i + d[s[i]][j] <= *mins[j].last().unwrap(); } } for i in 0..n { println!("{}", result[i].iter().map(|&v| if v { "Y" } else { "N" }).collect::>().join(" ")); } }