Buggy python submission (verdict: Time Limit Exceeded):
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, A, B, C = map(int, input().split())
    ans = []
    S = []
    for _ in range(N):
        S.append(input().rstrip('\n'))

    j_AB = 0
    j_BC = 0
    j_AC = 0
    for i in range(N):
        s = S[i]
        if s == "AB":
            if A == B == 0:
                print("No")
                exit()
            if A > B:
                A -= 1
                B += 1
                ans.append("B")
            elif A < B:
                A += 1
                B -= 1
                ans.append("A")
            else:
                if A > 1 or C > 0:
                    A += 1
                    B -= 1
                    ans.append("A")
                else:
                    if j_AB > i:
                        if j_AB == N:
                            A -= 1
                            B += 1
                            ans.append("B")
                        elif S[j_AB] == "BC":
                            A -= 1
                            B += 1
                            ans.append("B")
                        else:
                            A += 1
                            B -= 1
                            ans.append("A")
                    else:
                        j_AB = i+1
                        while True:
                            if S[j_AB] == "AB":
                                continue
                            j_AB += 1
                            if j_AB == N:
                                break
                        if j_AB > i:
                            if j_AB == N:
                                A -= 1
                                B += 1
                                ans.append("B")
                            elif S[j_AB] == "BC":
                                A -= 1
                                B += 1
                                ans.append("B")
                            else:
                                A += 1
                                B -= 1
                                ans.append("A")
        elif s == "BC":
            if B == C == 0:
                print("No")
                exit()
            if B > C:
                B -= 1
                C += 1
                ans.append("C")
            elif B < C:
                B += 1
                C -= 1
                ans.append("B")
            else:
                if B > 1 or A > 0:
                    B += 1
                    C -= 1
                    ans.append("B")
                else:
                    if j_BC > i:
                        if j_BC == N:
                            B -= 1
                            C += 1
                            ans.append("C")
                        elif S[j_BC] == "AC":
                            B -= 1
                            C += 1
                            ans.append("C")
                        else:
                            B += 1
                            C -= 1
                            ans.append("B")
                    else:
                        j_BC = i+1
                        while True:
                            if S[j_BC] == "BC":
                                continue
                            j_BC += 1
                            if j_BC == N:
                                break
                        if j_BC > i:
                            if j_BC == N:
                                B -= 1
                                C += 1
                                ans.append("C")
                            elif S[j_BC] == "AC":
                                B -= 1
                                C += 1
                                ans.append("C")
                            else:
                                B += 1
                                C -= 1
                                ans.append("B")
        elif s == "AC":
            if A == C == 0:
                print("No")
                exit()
            if A > C:
                A -= 1
                C += 1
                ans.append("C")
            elif A < C:
                A += 1
                C -= 1
                ans.append("A")
            else:
                if A > 1 or B > 0:
                    A += 1
                    C -= 1
                    ans.append("A")
                else:
                    if j_AC > i:
                        if j_AC == N:
                            A -= 1
                            C += 1
                            ans.append("C")
                        elif S[j_AC] == "BC":
                            A -= 1
                            C += 1
                            ans.append("C")
                        else:
                            A += 1
                            C -= 1
                            ans.append("A")
                    else:
                        j_AC = i+1
                        while True:
                            if S[j_AC] == "AC":
                                continue
                            j_AC += 1
                            if j_AC == N:
                                break
                        if j_AC > i:
                            if j_AC == N:
                                A -= 1
                                C += 1
                                ans.append("C")
                            elif S[j_AC] == "BC":
                                A -= 1
                                C += 1
                                ans.append("C")
                            else:
                                A += 1
                                C -= 1
                                ans.append("A")
    print("Yes")
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()


Fixed submission:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, A, B, C = map(int, input().split())
    ans = []
    S = []
    for _ in range(N):
        S.append(input().rstrip('\n'))

    j_AB = 0
    j_BC = 0
    j_AC = 0
    for i in range(N):
        s = S[i]
        if s == "AB":
            if A == B == 0:
                print("No")
                exit()
            if A > B:
                A -= 1
                B += 1
                ans.append("B")
            elif A < B:
                A += 1
                B -= 1
                ans.append("A")
            else:
                if A > 1 or C > 0:
                    A += 1
                    B -= 1
                    ans.append("A")
                else:
                    if j_AB > i:
                        if j_AB == N:
                            A -= 1
                            B += 1
                            ans.append("B")
                        elif S[j_AB] == "BC":
                            A -= 1
                            B += 1
                            ans.append("B")
                        else:
                            A += 1
                            B -= 1
                            ans.append("A")
                    else:
                        j_AB = i+1
                        if j_AB == N:
                            A -= 1
                            B += 1
                            ans.append("B")
                            continue
                        while True:
                            if S[j_AB] != "AB":
                                break
                            j_AB += 1
                            if j_AB == N:
                                break
                        if j_AB > i:
                            if j_AB == N:
                                A -= 1
                                B += 1
                                ans.append("B")
                            elif S[j_AB] == "BC":
                                A -= 1
                                B += 1
                                ans.append("B")
                            else:
                                A += 1
                                B -= 1
                                ans.append("A")
        elif s == "BC":
            if B == C == 0:
                print("No")
                exit()
            if B > C:
                B -= 1
                C += 1
                ans.append("C")
            elif B < C:
                B += 1
                C -= 1
                ans.append("B")
            else:
                if B > 1 or A > 0:
                    B += 1
                    C -= 1
                    ans.append("B")
                else:
                    if j_BC > i:
                        if j_BC == N:
                            B -= 1
                            C += 1
                            ans.append("C")
                        elif S[j_BC] == "AC":
                            B -= 1
                            C += 1
                            ans.append("C")
                        else:
                            B += 1
                            C -= 1
                            ans.append("B")
                    else:
                        j_BC = i+1
                        if j_BC == N:
                            B -= 1
                            C += 1
                            ans.append("C")
                            continue
                        while True:
                            if S[j_BC] != "BC":
                                break
                            j_BC += 1
                            if j_BC == N:
                                break
                        if j_BC > i:
                            if j_BC == N:
                                B -= 1
                                C += 1
                                ans.append("C")
                            elif S[j_BC] == "AC":
                                B -= 1
                                C += 1
                                ans.append("C")
                            else:
                                B += 1
                                C -= 1
                                ans.append("B")
        elif s == "AC":
            if A == C == 0:
                print("No")
                exit()
            if A > C:
                A -= 1
                C += 1
                ans.append("C")
            elif A < C:
                A += 1
                C -= 1
                ans.append("A")
            else:
                if A > 1 or B > 0:
                    A += 1
                    C -= 1
                    ans.append("A")
                else:
                    if j_AC > i:
                        if j_AC == N:
                            A -= 1
                            C += 1
                            ans.append("C")
                        elif S[j_AC] == "BC":
                            A -= 1
                            C += 1
                            ans.append("C")
                        else:
                            A += 1
                            C -= 1
                            ans.append("A")
                    else:
                        j_AC = i+1
                        if j_AC == N:
                            A -= 1
                            C += 1
                            ans.append("C")
                            continue
                        while True:
                            if S[j_AC] != "AC":
                                break
                            j_AC += 1
                            if j_AC == N:
                                break
                        if j_AC > i:
                            if j_AC == N:
                                A -= 1
                                C += 1
                                ans.append("C")
                            elif S[j_AC] == "BC":
                                A -= 1
                                C += 1
                                ans.append("C")
                            else:
                                A += 1
                                C -= 1
                                ans.append("A")
    print("Yes")
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()