macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        a: usize,
        b: usize,
        c: usize,
        v: [chars; n]
    }
    let mut dp = vec![vec![vec![vec![(0, 0, 0, 'S', false); 3]; 3]; 3]; n + 1];
    let ai = if a >= 2 {2} else {a};
    let bi = if b >= 2 {2} else {b};
    let ci = if c >= 2 {2} else {c};
    dp[0][ai][bi][ci].4 = true;
    for i in 0..n {
        if v[i] == vec!['A', 'B'] {
            for ai in 0..3 {
                for bi in 1..3 {
                    for ci in 0..3 {
                        if !dp[i][ai][bi][ci].4 {
                            continue;
                        }
                        if ai < 2 {
                            if dp[i + 1][ai + 1][bi - 1][ci].4 {
                                continue;
                            }
                            dp[i + 1][ai + 1][bi - 1][ci] = (ai, bi, ci, 'A', true);
                        } else {
                            if dp[i + 1][ai][bi - 1][ci].4 {
                                continue;
                            }
                            dp[i + 1][ai][bi - 1][ci] = (ai, bi, ci, 'A', true);
                        }
                    }
                }
            }
            for ai in 1..3 {
                for bi in 0..3 {
                    for ci in 0..3 {
                        if !dp[i][ai][bi][ci].4 {
                            continue;
                        }
                        if bi < 2 {
                            if dp[i + 1][ai - 1][bi + 1][ci].4 {
                                continue;
                            }
                            dp[i + 1][ai - 1][bi + 1][ci] = (ai, bi, ci, 'B', true);
                        } else {
                            if dp[i + 1][ai - 1][bi][ci].4 {
                                continue;
                            }
                            dp[i + 1][ai - 1][bi][ci] = (ai, bi, ci, 'B', true);
                        }
                    }
                }
            }
        } else if v[i] == vec!['A', 'C'] {
            for ai in 0..3 {
                for bi in 0..3 {
                    for ci in 1..3 {
                        if !dp[i][ai][bi][ci].4 {
                            continue;
                        }
                        if ai < 2 {
                            if dp[i + 1][ai + 1][bi][ci - 1].4 {
                                continue;
                            }
                            dp[i + 1][ai + 1][bi][ci - 1] = (ai, bi, ci, 'A', true);
                        } else {
                            if dp[i + 1][ai][bi][ci - 1].4 {
                                continue;
                            }
                            dp[i + 1][ai][bi][ci - 1] = (ai, bi, ci, 'A', true);
                        }
                    }
                }
            }
            for ai in 1..3 {
                for bi in 0..3 {
                    for ci in 0..3 {
                        if !dp[i][ai][bi][ci].4 {
                            continue;
                        }
                        if ci < 2 {
                            if dp[i + 1][ai - 1][bi][ci + 1].4 {
                                continue;
                            }
                            dp[i + 1][ai - 1][bi][ci + 1] = (ai, bi, ci, 'C', true);
                        } else {
                            if dp[i + 1][ai - 1][bi][ci].4 {
                                continue;
                            }
                            dp[i + 1][ai - 1][bi][ci] = (ai, bi, ci, 'C', true);
                        }
                    }
                }
            }
        } else {
            for ai in 0..3 {
                for bi in 0..3 {
                    for ci in 1..3 {
                        if !dp[i][ai][bi][ci].4 {
                            continue;
                        }
                        if bi < 2 {
                            if dp[i + 1][ai][bi + 1][ci - 1].4 {
                                continue;
                            }
                            dp[i + 1][ai][bi + 1][ci - 1] = (ai, bi, ci, 'B', true);
                        } else {
                            if dp[i + 1][ai][bi][ci - 1].4 {
                                continue;
                            }
                            dp[i + 1][ai][bi][ci - 1] = (ai, bi, ci, 'B', true);
                        }
                    }
                }
            }
            for ai in 0..3 {
                for bi in 1..3 {
                    for ci in 0..3 {
                        if !dp[i][ai][bi][ci].4 {
                            continue;
                        }
                        if ci < 2 {
                            if dp[i + 1][ai][bi - 1][ci + 1].4 {
                                continue;
                            }
                            dp[i + 1][ai][bi - 1][ci + 1] = (ai, bi, ci, 'C', true);
                        } else {
                            if dp[i + 1][ai][bi - 1][ci].4 {
                                continue;
                            }
                            dp[i + 1][ai][bi - 1][ci] = (ai, bi, ci, 'C', true);
                        }
                    }
                }
            }
        }
    }
    for i in 0..3 {
        for j in 0..3 {
            for k in 0..3 {
                if !dp[n][i][j][k].4 {
                    continue;
                }
                println!("Yes");
                let mut ai = i;
                let mut bi = j;
                let mut ci = k;
                let mut path = vec![];
                for i in (1..=n).rev() {
                    path.push(dp[i][ai][bi][ci].3);
                    let t = dp[i][ai][bi][ci];
                    ai = t.0;
                    bi = t.1;
                    ci = t.2;
                }
                for &c in path.iter().rev() {
                    println!("{}", c);
                }
                return;
            }
        }
    }
    println!("No");
}


Measured memory_bytes: 140036