Buggy python submission (verdict: Runtime Error):
*I, = open(0).read().split()
N, A, B, C = map(int, I[:4])
S = I[4:]

Cnt = {"A": A, "B": B, "C": C}

ans = [""] * N
def dfs(i):
    if i == N:
        print("Yes")
        print("\n".join(ans))
        quit()

    for L, R in (S[i], reversed(S[i])):
        if Cnt[R] > 0:
            Cnt[L] += 1
            Cnt[R] -= 1

            ans[i] = L
            dfs(i + 1)

            Cnt[L] -= 1
            Cnt[R] += 1


dfs(0)
print("No")


Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 6)

*I, = open(0).read().split()
N, A, B, C = map(int, I[:4])
S = I[4:]

Cnt = {"A": A, "B": B, "C": C}

ans = [""] * N
def dfs(i):
    if i == N:
        print("Yes")
        print("\n".join(ans))
        quit()

    for L, R in (S[i], reversed(S[i])):
        if Cnt[R] > 0:
            Cnt[L] += 1
            Cnt[R] -= 1

            ans[i] = L
            dfs(i + 1)

            Cnt[L] -= 1
            Cnt[R] += 1


dfs(0)
print("No")

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

ABC = {'A': A, 'B': B, 'C': C}
ans = [""] * N
# print('ABC : ' + str(ABC))

# Recursiveにすることによって、途中で負の値になってもいくらでも遡ることが可能となる
def recursive_exec(i):
  # 最後まで辿り着いたらクリア
  if i == N:
    print('Yes')
    print("\n".join(ans))
    quit()
  for L, R in (SN[i], reversed(SN[i])):	# ex) L, R in ('AB', 'BA')
    if ABC[L] > 0: # LでもRでもどちらでも良い
      ABC[L] -= 1
      ABC[R] += 1
      ans[i] = L

      # Next
      recursive_exec(i+1)

      # 0以下になったら戻して別の文字でやってみる (reversed(SN[i]))
      ABC[L] += 1
      ABC[R] -= 1

recursive_exec(0)
print('No')

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 6)

*I, = open(0).read().split()
N, A, B, C = map(int, I[:4])
S = I[4:]

Cnt = {"A": A, "B": B, "C": C}

ans = [""] * N
def dfs(i):
    if i == N:
        print("Yes")
        print("\n".join(ans))
        quit()

    for L, R in (S[i], reversed(S[i])):
        if Cnt[R] > 0:
            Cnt[L] += 1
            Cnt[R] -= 1

            ans[i] = L
            dfs(i + 1)

            Cnt[L] -= 1
            Cnt[R] += 1


dfs(0)
print("No")

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

ABC = {'A': A, 'B': B, 'C': C}
ans = [""] * N
# print('ABC : ' + str(ABC))

# Recursiveにすることによって、途中で負の値になってもいくらでも遡ることが可能となる
def recursive_exec(i):
  # 最後まで辿り着いたらクリア
  if i == N:
    print('OK')
    print("\n".join(ans))
    quit()
  for L, R in (SN[i], reversed(SN[i])):	# ex) L, R in ('AB', 'BA')
    if ABC[L] > 0: # LでもRでもどちらでも良い
      ABC[L] -= 1
      ABC[R] += 1
      ans[i] = L

      # Next
      recursive_exec(i+1)

      # 0以下になったら戻して別の文字でやってみる (reversed(SN[i]))
      ABC[L] += 1
      ABC[R] -= 1

recursive_exec(0)
print('NG')

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 6)

*I, = open(0).read().split()
N, A, B, C = map(int, I[:4])
S = I[4:]

Cnt = {"A": A, "B": B, "C": C}

ans = [""] * N
def dfs(i):
    if i == N:
        print("Yes")
        print("\n".join(ans))
        quit()

    for L, R in (S[i], reversed(S[i])):
        if Cnt[R] > 0:
            Cnt[L] += 1
            Cnt[R] -= 1

            ans[i] = L
            dfs(i + 1)

            Cnt[L] -= 1
            Cnt[R] += 1


dfs(0)
print("No")