Buggy python submission (verdict: Runtime Error):
N,A,B,C=map(int,input().split())
S = [input() for _ in range(N)]
table = [A,B,C]
ans = []

def ci(s):
    if s == 'AB':
        return 0,1
    elif s == 'BC':
        return 1,2
    else:
        return 0,2

if A+B+C == 0:
    print('No')
    exit()
elif A+B+C == 1:
    for s in S:
        i,j = ci(s)
        if table[i] == 0 and table[j] == 0:
            print('No')
            exit()
        else:
            if table[i] == 0:
                table[i] = 1
                table[j] = 0
                ans.append(i)
            else:
                table[j] = 1
                table[i] = 0
                ans.append(j)

else:
    for k in range(N):
        i,j= ci(S[k])
        if table[i] > table[j]:
            i,j = j,i
        # print(table,i,j)
        if k + 1 < N:
            i2,j2 = ci(S[k+1])
        if table[i] == 0 and table[j] == 0:
            print('No')
            exit()
        elif table[i] == 0 and table[j] > 0:
            table[i] += 1
            table[j] -= 1
            ans.append(i)
        else:
            table[i] += 1
            table[j] -= 1
            if table[i2] == 0 and table[j2] == 0:
                table[i] -= 2
                table[j] += 2
                ans.append(j)
            else:
                ans.append(i)

print('Yes')
L = ['A','B','C']
for a in ans:
    print(L[a])

Fixed submission:
N,A,B,C=map(int,input().split())
S = [input() for _ in range(N)]
table = [A,B,C]
ans = []

def ci(s):
    if s == 'AB':
        return 0,1
    elif s == 'BC':
        return 1,2
    else:
        return 0,2

if A+B+C == 0:
    print('No')
    exit()
elif A+B+C == 1:
    for s in S:
        i,j = ci(s)
        if table[i] == 0 and table[j] == 0:
            print('No')
            exit()
        else:
            if table[i] == 0:
                table[i] = 1
                table[j] = 0
                ans.append(i)
            else:
                table[j] = 1
                table[i] = 0
                ans.append(j)

else:
    for k in range(N):
        i,j= ci(S[k])
        if table[i] > table[j]:
            i,j = j,i
        # print(table,i,j)
        if k + 1 < N:
            i2,j2 = ci(S[k+1])
        if table[i] == 0 and table[j] == 0:
            print('No')
            exit()
        elif table[i] == 0 and table[j] > 0:
            table[i] += 1
            table[j] -= 1
            ans.append(i)
        else:
            table[i] += 1
            table[j] -= 1
            if k + 1 < N:
                if table[i2] == 0 and table[j2] == 0:
                    table[i] -= 2
                    table[j] += 2
                    ans.append(j)
                else:
                    ans.append(i)
            else:
                ans.append(i)

print('Yes')
L = ['A','B','C']
for a in ans:
    print(L[a])

Buggy python submission (verdict: Runtime Error):
N,A,B,C=map(int,input().split())
S = [input() for _ in range(N)]
table = [A,B,C]
ans = []

def ci(s):
    if s == 'AB':
        return 0,1
    elif s == 'BC':
        return 1,2
    else:
        return 0,2

if A+B+C == 0:
    print('No')
elif A+B+C == 1:
    for s in S:
        i,j = ci(s)
        if table[i] == 0 and table[j] == 0:
            print('No')
            exit()
        else:
            if table[i] == 0:
                table[i] = 1
                table[j] = 0
                ans.append(i)
            else:
                table[j] = 1
                table[i] = 0
                ans.append(j)

else:
    for k in range(N):
        i,j= ci(S[k])
        if table[i] > table[j]:
            i,j = j,i
        # print(table,i,j)
        if k + 1 < N:
            i2,j2 = ci(S[k+1])
        if table[i] == 0 and table[j] == 0:
            print('No')
            exit()
        elif table[i] == 0 and table[j] > 0:
            table[i] += 1
            table[j] -= 1
            ans.append(i)
        else:
            table[i] += 1
            table[j] -= 1
            if table[i2] == 0 and table[j2] == 0:
                table[i] -= 2
                table[j] += 2
                ans.append(j)
            else:
                ans.append(i)

print('Yes')
L = ['A','B','C']
for a in ans:
    print(L[a])

Fixed submission:
N,A,B,C=map(int,input().split())
S = [input() for _ in range(N)]
table = [A,B,C]
ans = []

def ci(s):
    if s == 'AB':
        return 0,1
    elif s == 'BC':
        return 1,2
    else:
        return 0,2

if A+B+C == 0:
    print('No')
    exit()
elif A+B+C == 1:
    for s in S:
        i,j = ci(s)
        if table[i] == 0 and table[j] == 0:
            print('No')
            exit()
        else:
            if table[i] == 0:
                table[i] = 1
                table[j] = 0
                ans.append(i)
            else:
                table[j] = 1
                table[i] = 0
                ans.append(j)

else:
    for k in range(N):
        i,j= ci(S[k])
        if table[i] > table[j]:
            i,j = j,i
        # print(table,i,j)
        if k + 1 < N:
            i2,j2 = ci(S[k+1])
        if table[i] == 0 and table[j] == 0:
            print('No')
            exit()
        elif table[i] == 0 and table[j] > 0:
            table[i] += 1
            table[j] -= 1
            ans.append(i)
        else:
            table[i] += 1
            table[j] -= 1
            if k + 1 < N:
                if table[i2] == 0 and table[j2] == 0:
                    table[i] -= 2
                    table[j] += 2
                    ans.append(j)
                else:
                    ans.append(i)
            else:
                ans.append(i)

print('Yes')
L = ['A','B','C']
for a in ans:
    print(L[a])

Buggy python submission (verdict: Runtime Error):
N,A,B,C=map(int,input().split())
S = [input() for _ in range(N)]
table = [A,B,C]
ans = []

def ci(s):
    if s == 'AB':
        return 0,1
    elif s == 'BC':
        return 1,2
    else:
        return 0,2

if A+B+C == 0:
    print('No')
elif A+B+C == 1:
    for s in S:
        i,j = ci(s)
        print(table,i,j)
        if table[i] == 0 and table[j] == 0:
            print('No')
            exit()
        else:
            if table[i] == 0:
                table[i] = 1
                table[j] = 0
                ans.append(i)
            else:
                table[j] = 1
                table[i] = 0
                ans.append(j)

else:
    for k in range(N):
        i,j= ci(S[k])
        if table[i] > table[j]:
            i,j = j,i
        # print(table,i,j)
        if k + 1 < N:
            i2,j2 = ci(S[k+1])
        if table[i] == 0 and table[j] == 0:
            print('No')
            exit()
        elif table[i] == 0 and table[j] > 0:
            table[i] += 1
            table[j] -= 1
            ans.append(i)
        else:
            table[i] += 1
            table[j] -= 1
            if table[i2] == 0 and table[j2] == 0:
                table[i] -= 2
                table[j] += 2
                ans.append(j)
            else:
                ans.append(i)

print('Yes')
L = ['A','B','C']
for a in ans:
    print(L[a])

Fixed submission:
N,A,B,C=map(int,input().split())
S = [input() for _ in range(N)]
table = [A,B,C]
ans = []

def ci(s):
    if s == 'AB':
        return 0,1
    elif s == 'BC':
        return 1,2
    else:
        return 0,2

if A+B+C == 0:
    print('No')
    exit()
elif A+B+C == 1:
    for s in S:
        i,j = ci(s)
        if table[i] == 0 and table[j] == 0:
            print('No')
            exit()
        else:
            if table[i] == 0:
                table[i] = 1
                table[j] = 0
                ans.append(i)
            else:
                table[j] = 1
                table[i] = 0
                ans.append(j)

else:
    for k in range(N):
        i,j= ci(S[k])
        if table[i] > table[j]:
            i,j = j,i
        # print(table,i,j)
        if k + 1 < N:
            i2,j2 = ci(S[k+1])
        if table[i] == 0 and table[j] == 0:
            print('No')
            exit()
        elif table[i] == 0 and table[j] > 0:
            table[i] += 1
            table[j] -= 1
            ans.append(i)
        else:
            table[i] += 1
            table[j] -= 1
            if k + 1 < N:
                if table[i2] == 0 and table[j2] == 0:
                    table[i] -= 2
                    table[j] += 2
                    ans.append(j)
                else:
                    ans.append(i)
            else:
                ans.append(i)

print('Yes')
L = ['A','B','C']
for a in ans:
    print(L[a])