Problem:
Score : 600 points

Problem Statement

There is a game that involves three variables, denoted A, B, and C.

As the game progresses, there will be N events where you are asked to make a choice.
Each of these choices is represented by a string s_i. If s_i is AB, you must add 1 to A or B then subtract 1 from the other; if s_i is AC, you must add 1 to A or C then subtract 1 from the other; if s_i is BC, you must add 1 to B or C then subtract 1 from the other.

After each choice, none of A, B, and C should be negative.

Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.

Constraints

1 \leq N \leq 10^5

0 \leq A,B,C \leq 10^9

N, A, B, C are integers.

s_i is AB, AC, or BC.

Input

Input is given from Standard Input in the following format:

N A B C
s_1
s_2
:
s_N

Output

If it is possible to make N choices under the condition, print Yes; otherwise, print No.

Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (A, B, or C) to which you add 1 in the i-th choice.

Sample Input 1

2 1 3 0
AB
AC

Sample Output 1

Yes
A
C

You can successfully make two choices, as follows:

In the first choice, add 1 to A and subtract 1 from B. A becomes 2, and B becomes 2.

In the second choice, add 1 to C and subtract 1 from A. C becomes 1, and A becomes 1.

Sample Input 2

3 1 0 0
AB
BC
AB

Sample Output 2

No

Sample Input 3

1 0 9 0
AC

Sample Output 3

No

Sample Input 4

8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB

Sample Output 4

Yes
C
B
B
C
C
B
A
A

Solution in C++ (GCC 9.2.1) (judge verdict: Runtime Error)

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using base = complex<double>;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define M2 998244353
#define ll long long
#define pll pair<long, long>
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define ff first
#define ss second
#define pb push_back
#define db pop_back
#define mp make_pair
#define mt make_tuple
#define g(a, b) get<a>(b)
#define INF (ll)3e18 + 100
#define vl vector<ll>
#define vi vector<int>
#define vll vector<pair<ll, ll>>
#define vii vector<pair<int, int>>
#define all(v) v.begin(), v.end()
#define bset(a, p) ((a) | (1ll << (p)))
#define bchk(a, p) ((a) & (1ll << (p)))
#define bxor(a, p) ((a) ^ (1ll << (p)));
#define brem(a, p) (bchk(a, p) ? (bxor(a, p)) : (a))
#define INT_SIZE 32
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
ll powM(ll x, ll y, ll m)
{
    ll ans = 1, r = 1;
    x %= m;
    while (r > 0 && r <= y)
    {
        if (r & y)
        {
            ans *= x;
            ans %= m;
        }
        r <<= 1;
        x *= x;
        x %= m;
    }
    return ans;
}
ll modI(ll a, ll m)
{
    ll m0 = m, y = 0, x = 1;
    if (m == 1)
        return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m;
        a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
        x += m0;
    return x;
}

ll logint(ll x, ll y)
{
    ll ans = 0;
    ll a = 1;
    for (ll i = 0; i <= x; i++)
    {
        if (x < a)
        {
            return ans;
        }
        ans++;
        a *= y;
    }
    return -1;
}
ll extended(ll a, ll b, ll &x, ll &y)
{
    if (a == 0)
    {
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll d = extended(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

// vector<int> prefix_function(string s) {
//     int n = (int)s.size();
//     vector<int> pi(n);
//     for (int i = 1; i < n; i++) {
//         int j = pi[i - 1];
//         while (j > 0 && s[i] != s[j])
//             j = pi[j - 1];
//         if (s[i] == s[j])
//             j++;
//         pi[i] = j;
//     }
//     return pi;
// }

// // vector<int>lps;
// // const int N = 5005;

// // vl dp(N, 0);
// void KMPSearch(string pattern, string text, int &cnt)
// {
//     int m = pattern.size();
//     int N = text.size();

//     // create lps[] that will hold the longest prefix suffix
//     // values for pattern

//     // Preprocess the pattern (calculate lps[] array)
//     vector<int>lps = prefix_function(pattern);

//     int i = 0; // index for txt[]
//     int j = 0; // index for pat[]
//     while (i < N) {
//         if (pattern[j] == text[i]) {
//             j++;
//             i++;
//         }

//         if (j == m) {
//             // cout << i - j << "\n";
//             cnt++;
//             // return;
//             j = lps[j - 1];
//         }

//         // mismatch after j matches
//         else if (i < N && pattern[j] != text[i]) {
//             // Do not match lps[0..lps[j-1]] characters,
//             // they will match anyway
//             if (j != 0)
//                 j = lps[j - 1];
//             else
//                 i = i + 1;
//         }
//     }
// }
// const int N = 1e6 + 5;
// vi factors[N];
// ll last[N];
// ll BIT[N];
// vector<pair<ll, ll>> query[N];
// vl prefix(N, 0);
// ll ask (ll k) {
//     ll s = 0;
//     while (k >= 1) {
//         s ^= BIT[k];
//         k -= k & -k;
//     }
//     return s;
// }

// void upd(ll k, ll x) {
//     while (k <= N) {
//         BIT[k] ^= x;
//         k += k & -k;
//     }
// }
const int N = 1e5+5;
vector<char>ans;
ll freq[N][3];
vector<string>st;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ll ntc;
    // cin >> ntc;
    ntc = 1;
    REP(tc, 1, ntc + 1)
    {
        // cout << "Case #" << tc << ": ";

        ll n, a, b, c;
        cin >> n >> a >> b >> c;
        memset(freq, 0, sizeof(freq));
        REP(i, 0, n) {
            string s;
            cin >> s;
            if (i != 0) {
                REP(j, 0, 3) {
                    freq[i][j] = freq[i - 1][j];
                }
            }
            REP(j, 0, 2) {
                freq[i][s[i] - 'A']++;
            }
            st.pb(s);
        }
        REP(i, 0, n) {
            string s = st[i];
            sort(all(s));
            if (s == "AB") {
                if (a > b) {
                    ans.pb('B');
                    b++;
                    a--;
                }
                else if (b > a) {
                    ans.pb('A');
                    a++;
                    b--;
                }
                else {
                    if (freq[n - 1][0] - freq[i][0] > freq[n - 1][1] - freq[i][1]) {
                        ans.pb('A');
                        a++;
                        b--;
                    }
                    else {
                        ans.pb('B');
                        b++;
                        a--;
                    }
                }
            }
            else if (s == "AC") {
                if (a > c) {
                    ans.pb('C');
                    c++;
                    a--;
                }
                else if (c > a) {
                    ans.pb('A');
                    a++;
                    c--;
                }
                else {
                    if (freq[n - 1][0] - freq[i][0] > freq[n - 1][2] - freq[i][2]) {
                        ans.pb('A');
                        a++;
                        c--;
                    }
                    else {
                        ans.pb('C');
                        c++;
                        a--;
                    }
                }
            }
            else {
                if (b > c) {
                    ans.pb('C');
                    c++;
                    b--;
                }
                else if (c > b) {
                    ans.pb('B');
                    b++;
                    c--;
                }
                else {
                    if (freq[n - 1][2] - freq[i][2] > freq[n - 1][1] - freq[i][1]) {
                        ans.pb('C');
                        b++;
                        c--;
                    }
                    else {
                        ans.pb('B');
                        c++;
                        b--;
                    }
                }
            }
            if (a < 0 || b < 0 || c < 0) {
                cout << "No";
                return 0;
            }
        }
        cout << "Yes\n";
        REP(i, 0, ans.size()) {
            cout << ans[i] << "\n";
        }
        // printf("Time taken: %.2fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
    }
}