Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


N, A, B, C = lmi()
S = [input().strip() for _ in range(N)]

a = A
b = B
total = A + B + C
ans = []
if total != 2:
    for s in S:
        c = total - a - b
        if s == "AB":
            if a == 0 and b == 0:
                print("No")
                exit()
            if a > b:
                a -= 1
                b += 1
                ans.append('B')
            else:
                a += 1
                b -= 1
                ans.append('A')
        if s == "AC":
            if a == 0 and c == 0:
                print("No")
                exit()
            if a > c:
                a -= 1
                ans.append('C')
            else:
                a += 1
                ans.append('A')
        if s == "BC":
            if b == 0 and c == 0:
                print("No")
                exit()
            if b > c:
                b -= 1
                ans.append('C')
            else:
                b += 1
                ans.append('B')
        # print(a,b,c)

    # print(ans, a, b, c)
    print('\n'.join(['Yes'] + ans))
    exit()

case = {(A, B, C): []}  # 1,1 1,0 0,1 0,0 2,0 0,2

for i, s in enumerate(S):
# while True:
#     s = input().strip()
    new_case = {}
    for (a, b, c), v in case.items():
        if s == "AB":
            if a == 0 and b == 0:
                continue
            elif a == 1 and b == 1:
                new_case[(0, 2, 0)] = list(v) + ['B']
                v.append('A')
                new_case[(2, 0, 0)] = v
                # two case
                pass
            else:
                v.append('A' if b else 'B')
                new_case[(abs(a - 1), abs(b - 1), c)] = v
        if s == "AC":
            if a == 0 and c == 0:
                continue
            if a == c:
                new_case[(2, 0, 0)] = list(v) + ['A']
                v.append('C')
                new_case[(0, 0, 2)] = v

                # two case
                pass
            else:
                v.append('C' if a else 'A')
                new_case[(abs(a - 1), b, abs(c-1))] = v

        if s == "BC":
            if b == 0 and c == 0:
                continue
            elif b == c:
                new_case[(0, 2, 0)] = list(v) + ['B']
                v.append('C')
                new_case[(0, 0, 2)] = v
            else:
                v.append('B' if c else 'C')
                new_case[(a ,abs( b-1), abs(c-1))] = v

    if not new_case:
        print("No")
        exit()
    case = new_case
    # print(case)

print('\n'.join(['Yes'] + list(case.values())[0]))


Fixed submission:
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


N, A, B, C = lmi()
S = [input().strip() for _ in range(N)]

a = A
b = B
total = A + B + C
ans = []
if total != 2:
    for s in S:
        c = total - a - b
        if s == "AB":
            if a == 0 and b == 0:
                print("No")
                exit()
            if a > b:
                a -= 1
                b += 1
                ans.append('B')
            else:
                a += 1
                b -= 1
                ans.append('A')
        if s == "AC":
            if a == 0 and c == 0:
                print("No")
                exit()
            if a > c:
                a -= 1
                ans.append('C')
            else:
                a += 1
                ans.append('A')
        if s == "BC":
            if b == 0 and c == 0:
                print("No")
                exit()
            if b > c:
                b -= 1
                ans.append('C')
            else:
                b += 1
                ans.append('B')
        # print(a,b,c)

    # print(ans, a, b, c)
    print('\n'.join(['Yes'] + ans))
    exit()

case = {(A, B, C): []}  # 1,1 1,0 0,1 0,0 2,0 0,2
ans = []

for i, s in enumerate(S):
    # while True:
    #     s = input().strip()
    new_case = {}
    for (a, b, c), v in case.items():
        if s == "AB":
            if a == 0 and b == 0:
                continue
            elif a == 1 and b == 1:
                new_case[(0, 2, 0)] = list(v) + ['B']
                v.append('A')
                new_case[(2, 0, 0)] = v
                # two case
                pass
            else:
                v.append('A' if b else 'B')
                new_case[(abs(a - 1), abs(b - 1), c)] = v
        if s == "AC":
            if a == 0 and c == 0:
                continue
            if a == c:
                new_case[(2, 0, 0)] = list(v) + ['A']
                v.append('C')
                new_case[(0, 0, 2)] = v

                # two case
                pass
            else:
                v.append('C' if a else 'A')
                new_case[(abs(a - 1), b, abs(c - 1))] = v

        if s == "BC":
            if b == 0 and c == 0:
                continue
            elif b == c:
                new_case[(0, 2, 0)] = list(v) + ['B']
                v.append('C')
                new_case[(0, 0, 2)] = v
            else:
                v.append('B' if c else 'C')
                new_case[(a, abs(b - 1), abs(c - 1))] = v

    if not new_case:
        print("No")
        exit()
    case = new_case
    if len(case) == 1:
        key = list(case.keys())[0]
        ans += case[key]
        case[key] = []

print('\n'.join(['Yes'] + ans + list(case.values())[0]))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


N, A, B, C = lmi()
S = [input().strip() for _ in range(N)]

a = A
b = B
total = A + B + C
ans = []
if total != 2:
    for s in S:
        c = total - a - b
        if s == "AB":
            if a == 0 and b == 0:
                print("No")
                exit()
            if a > b:
                a -= 1
                b += 1
                ans.append('B')
            else:
                a += 1
                b -= 1
                ans.append('A')
        if s == "AC":
            if a == 0 and c == 0:
                print("No")
                exit()
            if a > c:
                a -= 1
                ans.append('C')
            else:
                a += 1
                ans.append('A')
        if s == "BC":
            if b == 0 and c == 0:
                print("No")
                exit()
            if b > c:
                b -= 1
                ans.append('C')
            else:
                b += 1
                ans.append('B')
        # print(a,b,c)

    # print(ans, a, b, c)
    print('\n'.join(['Yes'] + ans))
    exit()

case = {(A, B, C): []}  # 1,1 1,0 0,1 0,0 2,0 0,2

for i, s in enumerate(S):
# while True:
#     s = input().strip()
    new_case = {}
    for (a, b, c), v in case.items():
        if s == "AB":
            if a == 0 and b == 0:
                continue
            elif a == 1 and b == 1:
                new_case[(0, 2, 0)] = list(v) + ['B']
                v.append('A')
                new_case[(2, 0, 0)] = v
                # two case
                pass
            else:
                v.append('A' if b else 'B')
                new_case[(abs(a - 1), abs(b - 1), c)] = v
        if s == "AC":
            if a == 0 and c == 0:
                continue
            if a == c:
                new_case[(2, 0, 0)] = list(v) + ['A']
                v.append('C')
                new_case[(0, 0, 2)] = v

                # two case
                pass
            else:
                v.append('C' if a else 'A')
                new_case[(abs(a - 1), b, abs(c-1))] = v

        if s == "BC":
            if b == 0 and c == 0:
                continue
            elif b == c:
                new_case[(0, 2, 0)] = list(v) + ['B']
                v.append('C')
                new_case[(0, 0, 2)] = v
            else:
                v.append('B' if c else 'C')
                new_case[(a ,abs( b-1), abs(c-1))] = v

    if not new_case:
        print("No")
        exit()
    case = new_case
    # print(case)

print('\n'.join(['Yes'] + list(case.values())[0]))


Fixed submission:
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


N, A, B, C = lmi()
S = [input().strip() for _ in range(N)]

a = A
b = B
total = A + B + C
ans = []
if total != 2:
    for s in S:
        c = total - a - b
        if s == "AB":
            if a == 0 and b == 0:
                print("No")
                exit()
            if a > b:
                a -= 1
                b += 1
                ans.append('B')
            else:
                a += 1
                b -= 1
                ans.append('A')
        if s == "AC":
            if a == 0 and c == 0:
                print("No")
                exit()
            if a > c:
                a -= 1
                ans.append('C')
            else:
                a += 1
                ans.append('A')
        if s == "BC":
            if b == 0 and c == 0:
                print("No")
                exit()
            if b > c:
                b -= 1
                ans.append('C')
            else:
                b += 1
                ans.append('B')
        # print(a,b,c)

    # print(ans, a, b, c)
    print('\n'.join(['Yes'] + ans))
    exit()

case = {(A, B, C): []}  # 1,1 1,0 0,1 0,0 2,0 0,2
ans = []

for i, s in enumerate(S):
    # while True:
    #     s = input().strip()
    new_case = {}
    for (a, b, c), v in case.items():
        if s == "AB":
            if a == 0 and b == 0:
                continue
            elif a == 1 and b == 1:
                new_case[(0, 2, 0)] = list(v) + ['B']
                v.append('A')
                new_case[(2, 0, 0)] = v
                # two case
                pass
            else:
                v.append('A' if b else 'B')
                new_case[(abs(a - 1), abs(b - 1), c)] = v
        if s == "AC":
            if a == 0 and c == 0:
                continue
            if a == c:
                new_case[(2, 0, 0)] = list(v) + ['A']
                v.append('C')
                new_case[(0, 0, 2)] = v

                # two case
                pass
            else:
                v.append('C' if a else 'A')
                new_case[(abs(a - 1), b, abs(c - 1))] = v

        if s == "BC":
            if b == 0 and c == 0:
                continue
            elif b == c:
                new_case[(0, 2, 0)] = list(v) + ['B']
                v.append('C')
                new_case[(0, 0, 2)] = v
            else:
                v.append('B' if c else 'C')
                new_case[(a, abs(b - 1), abs(c - 1))] = v

    if not new_case:
        print("No")
        exit()
    case = new_case
    if len(case) == 1:
        key = list(case.keys())[0]
        ans += case[key]
        case[key] = []

print('\n'.join(['Yes'] + ans + list(case.values())[0]))