Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import *

N, A, B, C = map(int, input().split())
s = [input()[:-1] for _ in range(N)]
ans = []

if A+B+C<=1 or A+B+C>=3:
    for si in s:
        if si=='AB':
            if A==0 and B==0:
                print('No')
                exit()
                
            if A<B:
                A += 1
                B -= 1
                ans.append('A')
            else:
                A -= 1
                B += 1
                ans.append('B')
        elif si=='AC':
            if A==0 and C==0:
                print('No')
                exit()
                
            if A<C:
                A += 1
                C -= 1
                ans.append('A')
            else:
                A -= 1
                C += 1
                ans.append('C')
        else:
            if B==0 and C==0:
                print('No')
                exit()
                
            if B<C:
                B += 1
                C -= 1
                ans.append('B')
            else:
                B -= 1
                C += 1
                ans.append('C')

    print('Yes')
    
    for ans_i in ans:
        print(ans_i)

    exit()
    
for i in range(N):
    if s[i]=='AB':
        if A==0 and B==0:
            print('No')
            exit()
            
        if A==0:
            A += 1
            B -= 1
            ans.append('A')
        elif B==0:
            A -= 1
            B += 1
            ans.append('B')
        else:
            if i<N-1 and s[i+1]=='AC':
                A += 1
                B -= 1
                ans.append('A')
            else:
                ans.append('B')
    elif s[i]=='AC':
        if A==0 and C==0:
            print('No')
            exit()
            
        if A==0:
            A += 1
            C -= 1
            ans.append('A')
        elif C==0:
            A -= 1
            C += 1
            ans.append('C')
        else:
            if i<N-1 and s[i+1]=='AB':
                A += 1
                C -= 1
                ans.append('A')
            else:
                ans.append('C')
    else:
        if B==0 and C==0:
            print('No')
            exit()
            
        if B==0:
            B += 1
            C -= 1
            ans.append('B')
        elif C==0:
            B -= 1
            C += 1
            ans.append('C')
        else:
            if i<N-1 and s[i+1]=='AB':
                B += 1
                C -= 1
                ans.append('B')
            else:
                ans.append('C')

    print('Yes')
    
    for ans_i in ans:
        print(ans_i)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import *

N, A, B, C = map(int, input().split())
l = [input()[:-1] for _ in range(N)]
ans = []

for i in range(N):
    if l[i]=='AB':
        if A==0:
            A += 1
            B -= 1
            ans.append('A')
        elif B==0:
            B += 1
            A -= 1
            ans.append('B')
        else:
            if i<N-1:
                if l[i+1]=='AB':
                    A += 1
                    B -= 1
                    ans.append('A')
                elif l[i+1]=='BC':
                    B += 1
                    A -= 1
                    ans.append('B')
                else:
                    A += 1
                    B -= 1
                    ans.append('A')
            else:
                ans.append('A')
    elif l[i]=='BC':
        if B==0:
            B += 1
            C -= 1
            ans.append('B')
        elif C==0:
            C += 1
            B -= 1
            ans.append('C')
        else:
            if i<N-1:
                if l[i+1]=='AB':
                    B += 1
                    C -= 1
                    ans.append('B')
                elif l[i+1]=='BC':
                    B += 1
                    C -= 1
                    ans.append('B')
                else:
                    C += 1
                    B -= 1
                    ans.append('C')
            else:
                ans.append('B')
    else:
        if A==0:
            A += 1
            C -= 1
            ans.append('A')
        elif C==0:
            C += 1
            A -= 1
            ans.append('C')
        else:
            if i<N-1:
                if l[i+1]=='AB':
                    A += 1
                    C -= 1
                    ans.append('A')
                elif l[i+1]=='BC':
                    C += 1
                    A -= 1
                    ans.append('C')
                else:
                    A += 1
                    C -= 1
                    ans.append('A')
            else:
                ans.append('A')
    
    if A<0 or B<0 or C<0:
        print('No')
        exit()
    
print('Yes')

for ans_i in ans:
    print(ans_i)