AtCoder Beginner Contest 166 - Three Variables Game

There is a game that involves three variables, denoted A, B, and C.
As the game progresses, there will be N events where you are asked to make a choice.
Each of these choices is represented by a string s_i. If s_i is AB, you must add 1 to A or B then subtract 1 from the other; if s_i is AC, you must add 1 to A or C then subtract 1 from the other; if s_i is BC, you must add 1 to B or C then subtract 1 from the other.
After each choice, none of A, B, and C should be negative.
Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.

-----Constraints-----
 - 1 \leq N \leq 10^5
 - 0 \leq A,B,C \leq 10^9
 - N, A, B, C are integers.
 - s_i is AB, AC, or BC.

-----Input-----
Input is given from Standard Input in the following format:
N A B C
s_1
s_2
:
s_N

-----Output-----
If it is possible to make N choices under the condition, print Yes; otherwise, print No.
Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (A, B, or C) to which you add 1 in the i-th choice.

-----Sample Input-----
2 1 3 0
AB
AC

-----Sample Output-----
Yes
A
C

You can successfully make two choices, as follows:
 - In the first choice, add 1 to A and subtract 1 from B. A becomes 2, and B becomes 2.
 - In the second choice, add 1 to C and subtract 1 from A. C becomes 1, and A becomes 1.

Source: atcoder | Difficulty: MEDIUM


Solutions:
import sys

def input():
	return sys.stdin.readline().strip()

def mapint():
	return map(int, input().split())
sys.setrecursionlimit(10 ** 9)
(N, A, B, C) = mapint()
costs = {'A': A, 'B': B, 'C': C}
(old_a, old_b) = list(input())
if costs[old_a] == 0 and costs[old_b] == 0:
	print('No')
	exit()
commands = []
for _ in range(N - 1):
	(nx_a, nx_b) = list(input())
	if costs[old_a] == 0 and costs[old_b] == 0:
		print('No')
		exit()
	elif costs[old_a] == 0:
		costs[old_a] += 1
		costs[old_b] -= 1
		commands.append(old_a)
	elif costs[old_b] == 0:
		costs[old_b] += 1
		costs[old_a] -= 1
		commands.append(old_b)
	elif old_a == nx_a or old_a == nx_b:
		commands.append(old_a)
		costs[old_a] += 1
		costs[old_b] -= 1
	else:
		commands.append(old_b)
		costs[old_b] += 1
		costs[old_a] -= 1
	(old_a, old_b) = (nx_a, nx_b)
if costs[old_a] == 0 and costs[old_b] == 0:
	print('No')
	exit()
elif costs[old_a] == 0:
	costs[old_a] += 1
	costs[old_b] -= 1
	commands.append(old_a)
else:
	costs[old_b] += 1
	costs[old_a] -= 1
	commands.append(old_b)
print('Yes')
print('\n'.join(commands))


(N, A, B, C) = map(int, input().split())
opts = []
for _ in range(N):
	opt = input()
	opts.append((ord(opt[0]) - ord('A'), ord(opt[1]) - ord('A')))
choices = []
nums = [A, B, C]
for (i, opt) in enumerate(opts):
	if nums[opt[0]] == 0 and nums[opt[1]] == 0:
		print('No')
		break
	if nums[opt[0]] == 1 and nums[opt[1]] == 1 and (i < N - 1) and (opt != opts[i + 1]):
		choice = (set(opt) & set(opts[i + 1])).pop()
	elif nums[opt[0]] >= nums[opt[1]]:
		choice = opt[1]
	else:
		choice = opt[0]
	choices.append(choice)
	nums[choice] += 1
	nums[choice ^ opt[0] ^ opt[1]] -= 1
else:
	print('Yes')
	for c in choices:
		print(chr(c + ord('A')))


import sys
YES = 'Yes'
NO = 'No'

def solve(N: int, A: int, B: int, C: int, s: 'List[int]'):
	v = [A, B, C]
	ans = []
	for i in range(N):
		(l, r) = s[i]
		if v[l] + v[r] == 0:
			return None
		if v[r] == 0 or (v[l] >= v[r] and i != N - 1 and (r in s[i + 1])):
			ans.append(r)
			v[l] -= 1
			v[r] += 1
		else:
			ans.append(l)
			v[l] += 1
			v[r] -= 1
	return ans

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word

	def s2index(s: 'List[str]'):
		return [ord(c) - ord('A') for c in s]

	def index2s(i: int):
		return chr(i + ord('A'))
	tokens = iterate_tokens()
	N = int(next(tokens))
	A = int(next(tokens))
	B = int(next(tokens))
	C = int(next(tokens))
	s = [s2index(next(tokens)) for _ in range(N)]
	ans = solve(N, A, B, C, s)
	if ans == None:
		print(NO)
	else:
		print(YES)
		print('\n'.join(list(map(index2s, ans))))
main()


(N, A, B, C) = map(int, input().split())
nums = [A, B, C]
steps = [input() for i in range(N)]
chars = ['A', 'B', 'C']
operations = []
can_select = True
for i in range(N):
	s = steps[i]
	left_idx = chars.index(s[0])
	right_idx = chars.index(s[1])
	if nums[left_idx] == 0 and nums[right_idx] == 0 or nums[left_idx] < 0 or nums[right_idx] < 0:
		can_select = False
		break
	elif nums[left_idx] == 1 and nums[right_idx] == 1 and (i != N - 1):
		if chars[left_idx] in list(steps[i + 1]):
			nums[left_idx] += 1
			nums[right_idx] -= 1
			operations.append(chars[left_idx])
		else:
			nums[left_idx] -= 1
			nums[right_idx] += 1
			operations.append(chars[right_idx])
	elif nums[left_idx] < nums[right_idx]:
		nums[left_idx] += 1
		nums[right_idx] -= 1
		operations.append(chars[left_idx])
	else:
		nums[left_idx] -= 1
		nums[right_idx] += 1
		operations.append(chars[right_idx])
if can_select:
	print('Yes')
	for i in operations:
		print(i)
else:
	print('No')


(n, a, b, c) = map(int, input().split())
g = [input() for i in range(n)]
sousa = []
for i in range(n):
	s = g[i]
	if s == 'AB':
		if a == 0 and b == 0:
			print('No')
			exit()
		if a == 1 and b == 0:
			sousa.append('B')
			a = 0
			b = 1
		elif a == 0 and b == 1:
			sousa.append('A')
			a = 1
			b = 0
		elif a > b:
			a -= 1
			b += 1
			sousa.append('B')
		elif a == b and i < n - 1 and (g[i + 1] == 'BC'):
			sousa.append('B')
			b += 1
			a -= 1
		else:
			b -= 1
			a += 1
			sousa.append('A')
	elif s == 'AC':
		if a == 0 and c == 0:
			print('No')
			exit()
		if a == 1 and c == 0:
			sousa.append('C')
			a = 0
			c = 1
		elif a == 0 and c == 1:
			sousa.append('A')
			a = 1
			c = 0
		elif a > c:
			a -= 1
			c += 1
			sousa.append('C')
		elif a == c and i < n - 1 and (g[i + 1] == 'BC'):
			sousa.append('C')
			a -= 1
			c += 1
		else:
			c -= 1
			a += 1
			sousa.append('A')
	else:
		if b == 0 and c == 0:
			print('No')
			exit()
		if c == 1 and b == 0:
			sousa.append('B')
			c = 0
			b = 1
		elif c == 0 and b == 1:
			sousa.append('C')
			c = 1
			b = 0
		elif c > b:
			c -= 1
			b += 1
			sousa.append('B')
		elif b == c and i < n - 1 and (g[i + 1] == 'AB'):
			sousa.append('B')
			b += 1
			c -= 1
		else:
			b -= 1
			c += 1
			sousa.append('C')
print('Yes')
for i in range(n):
	print(sousa[i])


import numpy as np

def resolve():
	(N, A, B, C) = map(int, input().split())
	Nlist = []
	YesOrNo = True
	ABC = str(input())
	for i in range(N):
		ABC_old = ABC
		if i < N - 1:
			ABC = str(input())
		if ABC_old == 'AB':
			if ABC == 'AC':
				add1 = np.sign(B - A + 0.1)
			else:
				add1 = np.sign(B - A - 0.1)
			if add1 < 0:
				Nlist.append('B')
			else:
				Nlist.append('A')
			A = A + add1
			B = B - add1
			if A < 0 or B < 0:
				YesOrNo = False
				print('No')
				break
		if ABC_old == 'AC':
			if ABC == 'AB':
				add1 = np.sign(C - A + 0.1)
			else:
				add1 = np.sign(C - A - 0.1)
			if add1 < 0:
				Nlist.append('C')
			else:
				Nlist.append('A')
			A = A + add1
			C = C - add1
			if A < 0 or C < 0:
				YesOrNo = False
				print('No')
				break
		if ABC_old == 'BC':
			if ABC == 'AB':
				add1 = np.sign(C - B + 0.1)
			else:
				add1 = np.sign(C - B - 0.1)
			if add1 < 0:
				Nlist.append('C')
			else:
				Nlist.append('B')
			B = B + add1
			C = C - add1
			if B < 0 or C < 0:
				YesOrNo = False
				print('No')
				break
	if YesOrNo:
		print('Yes')
		s_Nlist = '\n'.join(Nlist)
		print(s_Nlist)
resolve()


(n, a, b, c) = map(int, input().split())
s = []
for i in range(n):
	s.append(input())
ans = []
flag = True
for i in range(n):
	if s[i] == 'AB':
		if a < b:
			ans.append('A')
			a += 1
			b -= 1
		elif a == b == 1 and i < n - 1 and ('A' in s[i + 1]):
			ans.append('A')
			a += 1
			b -= 1
		elif a == b == 0:
			flag = False
			break
		else:
			ans.append('B')
			a -= 1
			b += 1
	if s[i] == 'AC':
		if a < c:
			ans.append('A')
			a += 1
			c -= 1
		elif a == c == 1 and i < n - 1 and ('A' in s[i + 1]):
			ans.append('A')
			a += 1
			c -= 1
		elif a == c == 0:
			flag = False
			break
		else:
			ans.append('C')
			a -= 1
			c += 1
	if s[i] == 'BC':
		if b < c:
			ans.append('B')
			b += 1
			c -= 1
		elif b == c == 1 and i < n - 1 and ('B' in s[i + 1]):
			ans.append('B')
			b += 1
			c -= 1
		elif b == c == 0:
			flag = False
			break
		else:
			ans.append('C')
			b -= 1
			c += 1
print('Yes' if flag else 'No')
if flag:
	for _ans in ans:
		print(_ans)


(N, A, B, C) = map(int, input().split())
vars = {'A': A, 'B': B, 'C': C}
sum_ABC = A + B + C
S = [input() for _ in range(N)]
Ans = []
for (s, s_next) in zip(S, S[1:]):
	if vars[s[0]] > vars[s[1]] or (vars[s[0]] == vars[s[1]] and s[1] in s_next):
		Ans.append(s[1])
		vars[s[1]] += 1
		vars[s[0]] -= 1
	else:
		Ans.append(s[0])
		vars[s[0]] += 1
		vars[s[1]] -= 1
	if vars[s[0]] < 0 or vars[s[1]] < 0:
		print('No')
		exit()
s = S[-1]
if vars[s[0]] > vars[s[1]]:
	Ans.append(s[1])
	vars[s[1]] += 1
	vars[s[0]] -= 1
else:
	Ans.append(s[0])
	vars[s[0]] += 1
	vars[s[1]] -= 1
if vars[s[0]] < 0 or vars[s[1]] < 0:
	print('No')
	exit()
print('Yes')
print('\n'.join(Ans))


(n, a, b, c) = map(int, input().split())
d = {'A': a, 'B': b, 'C': c}
ans = []

def move(inc, dec):
	d[inc] += 1
	d[dec] -= 1
	ans.append(inc)
q = []
for i in range(n):
	q.append(input())
for i in range(n):
	x = q[i][0]
	y = q[i][1]
	if d[x] == 0 and d[y] == 0:
		print('No')
		exit()
	if d[x] == 1 and d[y] == 1:
		if i == n - 1:
			move(x, y)
			continue
		if x in q[i + 1]:
			move(x, y)
		else:
			move(y, x)
	elif d[x] >= d[y]:
		move(y, x)
	else:
		move(x, y)
print('Yes')
print(*ans, sep='\n')


def solve(writer):
	(N, A, B, C) = list(map(int, input().split()))
	variables = {'A': A, 'B': B, 'C': C}
	queries = (list(input()) for _ in range(N))
	buffer = list()
	b = ''
	for i in range(N):
		if not buffer:
			(t1, t2) = next(queries)
		else:
			b = buffer.pop()
			if b == 'pass':
				continue
			else:
				(t1, t2) = list(b)
		v1 = variables[t1]
		v2 = variables[t2]
		if v1 == v2 == 0:
			return False
		elif v1 == v2 == 1:
			if i == N - 1:
				writer.append(t1)
				return True
			(nt1, nt2) = next(queries)
			if len({t1, t2, nt1, nt2}) == 2:
				buffer.append('pass')
				writer.append(t1)
				writer.append(t2)
				continue
			if t1 in {nt1, nt2}:
				variables[t1] += 1
				variables[t2] -= 1
				writer.append(t1)
			else:
				variables[t1] -= 1
				variables[t2] += 1
				writer.append(t2)
			buffer.append(''.join([nt1, nt2]))
		elif v1 > v2:
			variables[t1] -= 1
			variables[t2] += 1
			writer.append(t2)
		elif v2 > v1:
			variables[t1] += 1
			variables[t2] -= 1
			writer.append(t1)
		else:
			variables[t1] += 1
			variables[t2] -= 1
			writer.append(t1)
	return True

def main():
	writer = list()
	ok = solve(writer)
	if ok:
		print('Yes')
		for w in writer:
			print(w)
	else:
		print('No')

def __starting_point():
	main()
__starting_point()


def main():
	(N, A, B, C) = map(int, input().split())
	d = {'AB': (0, 1), 'AC': (0, 2), 'BC': (1, 2)}
	s = [d[input()] for _ in range(N)]
	abc = [A, B, C]
	ABC = 'ABC'
	ans = []
	for i in range(N):
		(x, y) = s[i]
		if abc[x] == abc[y] == 0:
			print('No')
			exit()
		if abc[x] == abc[y] == 1:
			if i == N - 1 or x in s[i + 1]:
				ans.append(ABC[x])
				abc[x] += 1
				abc[y] -= 1
			else:
				ans.append(ABC[y])
				abc[x] -= 1
				abc[y] += 1
		elif abc[x] > abc[y]:
			ans.append(ABC[y])
			abc[x] -= 1
			abc[y] += 1
		else:
			ans.append(ABC[x])
			abc[x] += 1
			abc[y] -= 1
	print('Yes')
	for a in ans:
		print(a)
main()


def abc(d, down_text, up_text):
	d[down_text] -= 1
	d[up_text] += 1

def main():
	(n, a, b, c) = map(int, input().split())
	ans_list = []
	dct = {'A': a, 'B': b, 'C': c}
	abc_list = [input() for _ in range(n)]
	abc_list.append('AB')
	for i in range(n):
		l_txt = abc_list[i][0]
		r_txt = abc_list[i][1]
		if dct[l_txt] < dct[r_txt]:
			abc(dct, r_txt, l_txt)
			ans_list.append(l_txt)
		elif dct[l_txt] > dct[r_txt]:
			abc(dct, l_txt, r_txt)
			ans_list.append(r_txt)
		elif dct[l_txt] == dct[r_txt] == 0:
			print('No')
			break
		elif l_txt in abc_list[i + 1]:
			abc(dct, r_txt, l_txt)
			ans_list.append(l_txt)
		elif r_txt in abc_list[i + 1]:
			abc(dct, l_txt, r_txt)
			ans_list.append(r_txt)
	else:
		print('Yes')
		print(*ans_list, sep='\n')
main()


import sys

def input():
	return sys.stdin.readline().strip()

def main():
	(N, A, B, C) = map(int, input().split())
	s = list((input() for _ in range(N)))
	d = {}
	d['A'] = A
	d['B'] = B
	d['C'] = C
	ans = []
	s.append('XX')
	for i in range(N):
		(l1, r1) = s[i]
		(l2, r2) = s[i + 1]

		def func(a, b):
			d[a] += 1
			d[b] -= 1
			ans.append(a)
		if d[l1] == 0 and d[r1] == 0:
			print('No')
			exit()
		if d[l1] == 0:
			func(l1, r1)
		elif d[r1] == 0:
			func(r1, l1)
		elif l1 in [l2, r2]:
			func(l1, r1)
		else:
			func(r1, l1)
	print('Yes')
	print(*ans, sep='\n')
main()


import sys
sys.setrecursionlimit(10 ** 6)
(N, A, B, C) = map(int, input().split())
Q = []
ans = []
f = 0

def dfs(f, a, b, c):
	if f == N:
		return True
	if Q[f] == 'AB':
		if a + b == 0:
			return False
		if b > 0 and dfs(f + 1, a + 1, b - 1, c):
			ans.append('A')
			return True
		if a > 0 and dfs(f + 1, a - 1, b + 1, c):
			ans.append('B')
			return True
		return False
	if Q[f] == 'BC':
		if c + b == 0:
			return False
		if c > 0 and dfs(f + 1, a, b + 1, c - 1):
			ans.append('B')
			return True
		if b > 0 and dfs(f + 1, a, b - 1, c + 1):
			ans.append('C')
			return True
		return False
	if Q[f] == 'AC':
		if a + c == 0:
			return False
		if c > 0 and dfs(f + 1, a + 1, b, c - 1):
			ans.append('A')
			return True
		if a > 0 and dfs(f + 1, a - 1, b, c + 1):
			ans.append('C')
			return True
		return False
for i in range(N):
	s = input()
	Q.append(s)
dfs(0, A, B, C)
if len(ans) == N:
	print('Yes')
	ans = ans[::-1]
	for i in ans:
		print(i)
else:
	print('No')


(n, a, b, c) = map(int, input().split())
s = [input() for i in range(n)]
dic = {'A': a, 'B': b, 'C': c}
ans = ['Yes']
for i in range(n):
	if dic[s[i][0]] == 0 and dic[s[i][1]] == 0:
		print('No')
		exit()
	elif dic[s[i][0]] == 0:
		dic[s[i][0]] += 1
		dic[s[i][1]] -= 1
		ans.append(s[i][0])
	elif dic[s[i][1]] == 0:
		dic[s[i][1]] += 1
		dic[s[i][0]] -= 1
		ans.append(s[i][1])
	elif i != n - 1:
		if s[i][0] in s[i + 1]:
			dic[s[i][0]] += 1
			dic[s[i][1]] -= 1
			ans.append(s[i][0])
		else:
			dic[s[i][1]] += 1
			dic[s[i][0]] -= 1
			ans.append(s[i][1])
	else:
		dic[s[i][0]] += 1
		dic[s[i][1]] -= 1
		ans.append(s[i][0])
print(*ans, sep='\n')


(N, A, B, C) = map(int, input().split())
S = [input() for _ in range(N)]
x = [A, B, C]
d = {'A': 0, 'B': 1, 'C': 2}
if sum(x) == 0:
	print('No')
else:
	flag = True
	ans = []
	for (i, s) in enumerate(S):
		(n, m) = list(s)
		if x[d[n]] == x[d[m]] == 0:
			flag = False
			break
		if x[d[n]] > x[d[m]]:
			x[d[n]] -= 1
			x[d[m]] += 1
			ans.append(m)
		elif x[d[n]] < x[d[m]]:
			x[d[n]] += 1
			x[d[m]] -= 1
			ans.append(n)
		elif i < N - 1 and S[i] != S[i + 1]:
			if n in S[i + 1]:
				x[d[n]] += 1
				x[d[m]] -= 1
				ans.append(n)
			else:
				x[d[m]] += 1
				x[d[n]] -= 1
				ans.append(m)
		else:
			x[d[n]] += 1
			x[d[m]] -= 1
			ans.append(n)
	if flag:
		print('Yes')
		print(*ans, sep='\n')
	else:
		print('No')


(n, a, b, c) = map(int, input().split())
d = {}
d['A'] = a
d['B'] = b
d['C'] = c
pl = [input() for _ in range(n)]
res = []
for i in range(n):
	p = pl[i]
	if d[p[0]] == d[p[1]] == 0:
		print('No')
		exit()
	elif d[p[0]] == 0:
		res.append(p[0])
		d[p[0]] += 1
		d[p[1]] -= 1
	elif d[p[1]] == 0:
		res.append(p[1])
		d[p[0]] -= 1
		d[p[1]] += 1
	elif i == n - 1:
		res.append(p[0])
	elif p[0] in pl[i + 1]:
		res.append(p[0])
		d[p[0]] += 1
		d[p[1]] -= 1
	else:
		res.append(p[1])
		d[p[0]] -= 1
		d[p[1]] += 1
print('Yes')
for p in res:
	print(p)


import sys
sys.setrecursionlimit(10 ** 5 + 10)
(N, A, B, C) = [int(i) for i in input().split()]
ans = list()
l = list()
for n in range(N):
	l.append(input())

def dfs(i, a, b, c):
	if i == N:
		return True
	ss = l[i]
	if ss == 'AB':
		if a == 0 and b == 0:
			return False
		if b > 0 and dfs(i + 1, a + 1, b - 1, c):
			ans.append('A')
			return True
		if a > 0 and dfs(i + 1, a - 1, b + 1, c):
			ans.append('B')
			return True
	if ss == 'AC':
		if a == 0 and c == 0:
			return False
		if c > 0 and dfs(i + 1, a + 1, b, c - 1):
			ans.append('A')
			return True
		if a > 0 and dfs(i + 1, a - 1, b, c + 1):
			ans.append('C')
			return True
	if ss == 'BC':
		if b == 0 and c == 0:
			return False
		if c > 0 and dfs(i + 1, a, b + 1, c - 1):
			ans.append('B')
			return True
		if b > 0 and dfs(i + 1, a, b - 1, c + 1):
			ans.append('C')
			return True
	return False
dfs(0, A, B, C)
if len(ans) > 0:
	print('Yes')
	for x in reversed(ans):
		print(x)
else:
	print('No')


def put(ret, val):
	if val == 0:
		ret.append('A')
	elif val == 1:
		ret.append('B')
	else:
		ret.append('C')
(n, a, b, c) = list(map(int, input().split()))
s = []
for i in range(n):
	tmp = input()
	if tmp == 'AB':
		val = 0
	elif tmp == 'BC':
		val = 1
	else:
		val = 2
	s.append(val)
ret = []
if a + b + c == 0:
	print('No')
	return
elif a + b + c == 1:
	t = []
	t.append(a)
	t.append(b)
	t.append(c)
	for (i, item) in enumerate(s):
		if t[item] == 1:
			t[item] = 0
			t[(item + 1) % 3] = 1
			put(ret, (item + 1) % 3)
		elif t[(item + 1) % 3] == 1:
			t[item] = 1
			t[(item + 1) % 3] = 0
			put(ret, item)
		else:
			print('No')
			return
elif a + b + c == 2:
	t = []
	t.append(a)
	t.append(b)
	t.append(c)
	for (i, item) in enumerate(s):
		if t[item] == 0 and t[(item + 1) % 3] == 0:
			print('No')
			return
		if t[item] > t[(item + 1) % 3]:
			t[item] -= 1
			t[(item + 1) % 3] += 1
			put(ret, (item + 1) % 3)
		elif t[item] < t[(item + 1) % 3]:
			t[item] += 1
			t[(item + 1) % 3] -= 1
			put(ret, item)
		elif t[item] == 0:
			print('No')
			return
		elif t[item] == 2:
			t[item] -= 1
			t[(item + 1) % 3] += 1
			put(ret, (item + 1) % 3)
		elif len(s) > i + 1:
			if s[i + 1] == (item + 1) % 3:
				t[item] -= 1
				t[(item + 1) % 3] += 1
				put(ret, (item + 1) % 3)
			else:
				t[item] += 1
				t[(item + 1) % 3] -= 1
				put(ret, item)
		else:
			put(ret, item)
else:
	t = []
	t.append(a)
	t.append(b)
	t.append(c)
	for (i, item) in enumerate(s):
		if t[item] == 0 and t[(item + 1) % 3] == 0:
			print('No')
			return
		if t[item] > t[(item + 1) % 3]:
			t[item] -= 1
			t[(item + 1) % 3] += 1
			put(ret, (item + 1) % 3)
		else:
			t[item] += 1
			t[(item + 1) % 3] -= 1
			put(ret, item)
print('Yes')
for item in ret:
	print(item)


def main():
	(N, A, B, C) = list(map(int, input().split()))
	array = [A, B, C]
	string = ['A', 'B', 'C']
	si = []
	if A + B + C <= 0:
		print('No')
		return
	for _ in range(N):
		s = input()
		si += (0 if s == 'AB' else 1 if s == 'BC' else 2,)
	ans = []
	for i in range(len(si)):
		s = si[i]
		index = -3 if s == 0 else -2 if s == 1 else -1
		if array[index] == 0:
			array[index] += 1
			array[index + 1] -= 1
			ans += (string[index],)
		elif array[index + 1] == 0:
			array[index] -= 1
			array[index + 1] += 1
			ans += (string[index + 1],)
		elif array[index] == 1 and array[index + 1] == 1:
			if i + 1 >= len(si):
				array[index] += 1
				array[index + 1] -= 1
				ans += (string[index],)
			elif si[i + 1] != (index + 1) % 3:
				array[index] += 1
				array[index + 1] -= 1
				ans += (string[index],)
			else:
				array[index] -= 1
				array[index + 1] += 1
				ans += (string[index + 1],)
		elif array[index] == 1:
			array[index] += 1
			array[index + 1] -= 1
			ans += (string[index],)
		else:
			array[index] -= 1
			array[index + 1] += 1
			ans += (string[index + 1],)
		if array[0] < 0 or array[1] < 0 or array[2] < 0:
			print('No')
			return
	print('Yes')
	for s in ans:
		print(s)
main()


import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
(N, A, B, C) = map(int, input().split())
S = [input().strip('\n').replace('A', '0').replace('B', '1').replace('C', '2') for _ in range(N)]
Ans = [None] * N

def search(i, num):
	if i == N:
		if min(num) >= 0:
			return True
		else:
			return False
	if min(num) < 0:
		return False
	L = [num[0], num[1], num[2]]
	f = S[i][0]
	s = S[i][1]
	L[int(f)] += 1
	L[int(s)] -= 1
	if search(i + 1, L):
		Ans[i] = f
		return True
	L[int(f)] -= 2
	L[int(s)] += 2
	if search(i + 1, L):
		Ans[i] = s
		return True
	return False

def solve():
	if search(0, [A, B, C]):
		print('Yes')
		for (i, a) in enumerate(Ans):
			if a == '0':
				print('A')
			elif a == '1':
				print('B')
			else:
				print('C')
	else:
		print('No')
	return 0
solve()


def change(d, ans, X, Y):
	z = {'A': 0, 'B': 1, 'C': 2}
	d[z[X]] += 1
	d[z[Y]] -= 1
	ans.append(X)
	return (d, ans)
(n, a, b, c) = map(int, input().split())
d = [a, b, c]
q = [input() for i in range(n)]
z = {'A': 0, 'B': 1, 'C': 2}
if sum(d) == 0:
	print('No')
elif sum(d) == 1:
	ans = []
	for i in range(n):
		X = q[i][0]
		Y = q[i][1]
		if d[z[X]] > 0:
			(d, ans) = change(d, ans, Y, X)
		elif d[z[Y]] > 0:
			(d, ans) = change(d, ans, X, Y)
		else:
			print('No')
			exit()
	print('Yes')
	print('\n'.join(ans))
else:
	ans = []
	X = q[0][0]
	Y = q[0][1]
	if d[z[X]] == d[z[Y]] == 0:
		print('No')
		exit()
	for i in range(n - 1):
		X = q[i][0]
		Y = q[i][1]
		if d[z[X]] == 0:
			(d, ans) = change(d, ans, X, Y)
		elif d[z[Y]] == 0:
			(d, ans) = change(d, ans, Y, X)
		elif X in q[i + 1]:
			(d, ans) = change(d, ans, X, Y)
		elif Y in q[i + 1]:
			(d, ans) = change(d, ans, Y, X)
	X = q[-1][0]
	Y = q[-1][1]
	if d[z[X]] > 0:
		ans.append(Y)
	else:
		ans.append(X)
	print('Yes')
	print('\n'.join(ans))


(n, a, b, c) = map(int, input().split(' '))
left = [a, b, c]
ans = []
prev = (-1, -1)
for i in range(0, n):
	s = input()
	x = {'A': 0, 'B': 1, 'C': 2}[s[0]]
	y = {'A': 0, 'B': 1, 'C': 2}[s[1]]
	if left[x] == left[y] == 0:
		(x0, y0) = prev
		if x0 != -1:
			left[x0] -= 1
			left[y0] += 1
			if left[x0] == 0:
				ans = []
				break
			left[x0] -= 1
			left[y0] += 1
			ans[len(ans) - 1] = 'ABC'[y0]
		else:
			ans = []
			break
	if left[x] > left[y]:
		(x, y) = (y, x)
	left[x] += 1
	left[y] -= 1
	ans.append('ABC'[x])
	prev = (x, y)
if len(ans) == 0:
	print('No')
else:
	print('Yes')
	for x in ans:
		print(x)


(n, a, b, c) = map(int, input().split())
q = [(0, 1) if si == 'AB' else (1, 2) if si == 'BC' else (0, 2) for si in (input() for _ in range(n))]
ans = []
ch = ['A', 'B', 'C']
d = [a, b, c]
nxt = [[-1] * 3] * n
t = [-1, -1, -1]
for (i, (x, y)) in reversed(list(enumerate(q))):
	nxt[i] = t.copy()
	(t[x], t[y]) = (y, x)
for ((x, y), t) in zip(q, nxt):
	if d[x] == d[y] == 0:
		print('No')
		break
	if d[x] != 0 and (d[y] == 0 or d[x] >= 2 or t[3 - x - y] == y):
		(x, y) = (y, x)
	d[x] += 1
	d[y] -= 1
	ans.append(ch[x])
else:
	print('Yes', *ans, sep='\n')


import sys
sys.setrecursionlimit(10 ** 7)
INF = float('inf')
MOD = 10 ** 9 + 7
(N, A, B, C) = list(map(int, input().split()))
num = [A, B, C]
S = []
for i in range(N):
	S.append(input().strip())
S.append('AB')
ans = []
for i in range(N):
	s1 = S[i][0]
	s2 = S[i][1]
	n1 = num['ABC'.index(s1)]
	n2 = num['ABC'.index(s2)]
	if n1 == n2 == 0:
		print('No')
		return
	s_add = ''
	s_sub = ''
	if n1 == 0:
		s_add = s1
		s_sub = s2
	elif n2 == 0:
		s_add = s2
		s_sub = s1
	elif s1 in S[i + 1]:
		s_add = s1
		s_sub = s2
	else:
		s_add = s2
		s_sub = s1
	num['ABC'.index(s_add)] += 1
	num['ABC'.index(s_sub)] -= 1
	ans.append(s_add)
print('Yes')
for a in ans:
	print(a)


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
(n, a, b, c) = map(int, readline().split())
s = [readline().rstrip().decode() for _ in range(n)] + ['']
ans = [''] * n
for (i, (bf, af)) in enumerate(zip(s, s[1:])):
	if bf == 'AB':
		if a > b or (a == b and i != n - 1 and ('B' in af)):
			b += 1
			a -= 1
			ans[i] = 'B'
		else:
			a += 1
			b -= 1
			ans[i] = 'A'
	elif bf == 'AC':
		if a > c or (a == c and i != n - 1 and ('C' in af)):
			c += 1
			a -= 1
			ans[i] = 'C'
		else:
			c -= 1
			a += 1
			ans[i] = 'A'
	elif b > c or (b == c and i != n - 1 and ('C' in af)):
		c += 1
		b -= 1
		ans[i] = 'C'
	else:
		c -= 1
		b += 1
		ans[i] = 'B'
	if a < 0 or b < 0 or c < 0:
		print('No')
		exit()
print('Yes')
print('\n'.join(ans))


import sys
sys.setrecursionlimit(10 ** 7)
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
printn = lambda x: print('\n'.join(x))
(n, a, b, c) = nm()
d = {'A': a, 'B': b, 'C': c}
l = [input() for _ in range(n)] + ['#']
ans = list()
for i in range(n):
	(u, v) = l[i]
	if d[u] <= d[v]:
		(u, v) = (v, u)
	if d[u] == d[v] and u in l[i + 1]:
		(u, v) = (v, u)
	ans.append(v)
	d[u] -= 1
	d[v] += 1
	if d[u] < 0:
		print('No')
		exit(0)
print('Yes')
printn(ans)


X = [0, 0, 0]
(N, X[0], X[1], X[2]) = map(int, input().split())
Q = []
for _ in range(N):
	s = input()
	if s == 'AB':
		Q.append([0, 1])
	elif s == 'AC':
		Q.append([0, 2])
	else:
		Q.append([1, 2])
ans = True
ret = ''
for i in range(N):
	a = Q[i][0]
	b = Q[i][1]
	if X[a] == X[b] == 0:
		ans = False
		break
	elif X[a] < X[b]:
		ret += chr(ord(str(a)) + 17)
		X[a] += 1
		X[b] -= 1
	elif X[a] > X[b] or i == N - 1:
		ret += chr(ord(str(b)) + 17)
		X[a] -= 1
		X[b] += 1
	else:
		s = Q[i + 1][0]
		t = Q[i + 1][1]
		if a == s or a == t:
			ret += chr(ord(str(a)) + 17)
			X[a] += 1
			X[b] -= 1
		else:
			ret += chr(ord(str(b)) + 17)
			X[a] -= 1
			X[b] += 1
	if X[a] < 0 or X[b] < 0:
		ans = False
		break
if ans:
	print('Yes')
	print('\n'.join(ret))
else:
	print('No')


(n, a, b, c) = map(int, input().split())
d = {'A': a, 'B': b, 'C': c}
ns = []
for i in range(n):
	ns.append(input())
path = []
flag = True
for (i, j) in enumerate(ns):
	(x, y) = j
	if d[x] > d[y]:
		d[x] -= 1
		d[y] += 1
		path.append(y)
	elif d[x] < d[y]:
		d[x] += 1
		d[y] -= 1
		path.append(x)
	else:
		if d[x] == 0:
			flag = False
			print('No')
			break
		if i + 1 < n:
			if x in ns[i + 1]:
				d[x] += 1
				d[y] -= 1
				path.append(x)
			else:
				d[y] += 1
				d[x] -= 1
				path.append(y)
		else:
			path.append(x)
if flag:
	print('Yes')
	for i in path:
		print(i)


(n, a, b, c) = map(int, input().split())
ss = []
for i in range(n):
	ss.append(input())
ans = []
tower = [a, b, c]
s2num = {'AB': [0, 1], 'BC': [1, 2], 'AC': [0, 2]}
num2s = {0: 'A', 1: 'B', 2: 'C'}
flag = True

def check_large(l, r, t):
	if t[l] > t[r]:
		return (l, r, False)
	elif t[l] < t[r]:
		return (r, l, False)
	else:
		return (l, r, True)
for i in range(n):
	s = ss[i]
	(l, r) = s2num[s]
	(big, small, f) = check_large(l, r, tower)
	if f:
		if i + 1 < n:
			nex = s2num[ss[i + 1]]
			if big in nex:
				(small, big) = (big, small)
	if tower[big] <= 0:
		flag = False
		break
	else:
		tower[big] -= 1
		tower[small] += 1
		ans.append(num2s[small])
if flag:
	print('Yes')
	for i in range(n):
		print(ans[i])
else:
	print('No')


(n, a, b, c) = list(map(int, input().split()))
s = [list(input()) for _ in range(n)]
s.append(['A', 'B'])
d = {'A': a, 'B': b, 'C': c}
ans = []

def calc(add, sub):
	d[add] += 1
	d[sub] -= 1
	ans.append(add)
for (i, [j, k]) in enumerate(s):
	if i == n:
		print('Yes')
		print('\n'.join(ans))
		break
	if d[j] == 0 and d[k] == 0:
		print('No')
		break
	elif j == 'A' and k == 'B':
		if d[j] < d[k]:
			calc(j, k)
		elif d[j] > d[k]:
			calc(k, j)
		elif s[i + 1][0] == 'A':
			calc(j, k)
		else:
			calc(k, j)
	elif j == 'A' and k == 'C':
		if d[j] < d[k]:
			calc(j, k)
		elif d[j] > d[k]:
			calc(k, j)
		elif s[i + 1][0] == 'A':
			calc(j, k)
		else:
			calc(k, j)
	elif j == 'B' and k == 'C':
		if d[j] < d[k]:
			calc(j, k)
		elif d[j] > d[k]:
			calc(k, j)
		elif s[i + 1][0] == 'A' and s[i + 1][1] == 'C':
			calc(k, j)
		else:
			calc(j, k)


import sys
dict_in = {'AB': [0, 1], 'AC': [0, 2], 'BC': [1, 2]}
dict_out = {0: 'A', 1: 'B', 2: 'C'}
(n, a, b, c) = map(int, input().split())
var = [a, b, c]
s = [dict_in[input()] for i in range(n)]
ans = []
for i in range(n):
	if var[s[i][0]] > var[s[i][1]]:
		var[s[i][0]] -= 1
		var[s[i][1]] += 1
		ans.append(dict_out[s[i][1]])
	elif var[s[i][0]] < var[s[i][1]]:
		var[s[i][0]] += 1
		var[s[i][1]] -= 1
		ans.append(dict_out[s[i][0]])
	else:
		if var[s[i][0]] == 0 and var[s[i][1]] == 0:
			print('No')
			sys.exit()
		inc = s[i][1]
		for j in range(i + 1, n):
			if not s[i][0] in s[j]:
				inc = s[i][1]
				break
			elif not s[i][1] in s[j]:
				inc = s[i][0]
				var[s[i][0]] += 1
				var[s[i][1]] -= 1
				break
		if inc == s[i][1]:
			var[s[i][0]] -= 1
			var[s[i][1]] += 1
		ans.append(dict_out[inc])
print('Yes')
for i in range(len(ans)):
	print(ans[i])


(n, a, b, c) = map(int, input().split())
s = [input() for _ in range(n)]
if a + b + c == 0:
	print('No')
if a + b + c == 1 or a + b + c >= 3:
	ans = []
	for i in s:
		if i == 'AB':
			if a < b:
				ans.append('A')
				a += 1
				b += -1
				c += 0
			else:
				ans.append('B')
				a += -1
				b += 1
				c += 0
		if i == 'BC':
			if b < c:
				ans.append('B')
				a += 0
				b += 1
				c += -1
			else:
				ans.append('C')
				a += 0
				b += -1
				c += 1
		if i == 'AC':
			if a < c:
				ans.append('A')
				a += 1
				b += 0
				c += -1
			else:
				ans.append('C')
				a += -1
				b += 0
				c += 1
		if min(a, b, c) < 0:
			print('No')
			return
	print('Yes')
	for i in ans:
		print(i)
if a + b + c == 2:
	ans = []
	for i in range(n - 1):
		if s[i] == 'AB':
			if a == b:
				if s[i + 1] == 'AC':
					ans.append('A')
					a += 1
					b += -1
					c += 0
				else:
					ans.append('B')
					a += -1
					b += 1
					c += 0
			elif a < b:
				ans.append('A')
				a += 1
				b += -1
				c += 0
			else:
				ans.append('B')
				a += -1
				b += 1
				c += 0
		if s[i] == 'BC':
			if b == c:
				if s[i + 1] == 'AC':
					ans.append('C')
					a += 0
					b += -1
					c += 1
				else:
					ans.append('B')
					a += 0
					b += 1
					c += -1
			elif b < c:
				ans.append('B')
				a += 0
				b += 1
				c += -1
			else:
				ans.append('C')
				a += 0
				b += -1
				c += 1
		if s[i] == 'AC':
			if a == c:
				if s[i + 1] == 'BC':
					ans.append('C')
					a += -1
					b += 0
					c += 1
				else:
					ans.append('A')
					a += 1
					b += 0
					c += -1
			elif a < c:
				ans.append('A')
				a += 1
				b += 0
				c += -1
			else:
				ans.append('C')
				a += -1
				b += 0
				c += 1
		if min(a, b, c) < 0:
			print('No')
			return
	for i in s[n - 1:]:
		if i == 'AB':
			if a < b:
				ans.append('A')
				a += 1
				b += -1
				c += 0
			else:
				ans.append('B')
				a += -1
				b += 1
				c += 0
		if i == 'BC':
			if b < c:
				ans.append('B')
				a += 0
				b += 1
				c += -1
			else:
				ans.append('C')
				a += 0
				b += -1
				c += 1
		if i == 'AC':
			if a < c:
				ans.append('A')
				a += 1
				b += 0
				c += -1
			else:
				ans.append('C')
				a += -1
				b += 0
				c += 1
		if min(a, b, c) < 0:
			print('No')
			return
	print('Yes')
	for i in ans:
		print(i)


(N, A, B, C) = list(map(int, input().split()))
d = {'A': A, 'B': B, 'C': C}
res = []
SN = [input() for i in range(N)]
for i in range(N):
	s = SN[i]
	s0 = s[0]
	s1 = s[1]
	if d[s0] == d[s1] == 0:
		print('No')
		exit()
	elif d[s0] == 0:
		d[s0] += 1
		d[s1] -= 1
		res.append(s0)
	elif d[s1] == 0:
		d[s0] -= 1
		d[s1] += 1
		res.append(s1)
	elif i == N - 1:
		res.append(s0)
	elif s0 in SN[i + 1]:
		d[s0] += 1
		d[s1] -= 1
		res.append(s0)
	else:
		d[s0] -= 1
		d[s1] += 1
		res.append(s1)
print('Yes')
for r in res:
	print(r)


(n, a, b, c) = list(map(int, input().split()))
abc = [a, b, c]
s = [tuple(map(lambda x: ord(x) - 97, list(input().lower()))) for i in range(n)]
from copy import deepcopy
s.append(deepcopy(s[-1]))
ret = True
ret_choice = []
ra = ret_choice.append
for (i, j) in zip(s, s[1:]):
	if abc[i[0]] >= 3 and abc[i[1]] >= 3:
		abc[i[0]] += 1
		abc[i[1]] -= 1
		ra(i[0])
	elif abc[i[0]] >= 3 and abc[i[1]] < 3:
		abc[i[0]] -= 1
		abc[i[1]] += 1
		ra(i[1])
	elif abc[i[0]] < 3 and abc[i[1]] >= 3:
		abc[i[0]] += 1
		abc[i[1]] -= 1
		ra(i[0])
	elif abc[i[0]] == 0:
		abc[i[0]] += 1
		abc[i[1]] -= 1
		ra(i[0])
	elif abc[i[1]] == 0:
		abc[i[0]] -= 1
		abc[i[1]] += 1
		ra(i[1])
	elif i[0] in j:
		abc[i[0]] += 1
		abc[i[1]] -= 1
		ra(i[0])
	else:
		abc[i[0]] -= 1
		abc[i[1]] += 1
		ra(i[1])
	if -1 in abc:
		ret = False
		break
if ret:
	print('Yes')
	for i in map(lambda x: chr(x + 65), ret_choice):
		print(i)
else:
	print('No')


(n, a, b, c) = map(int, input().split())
si = [input() for i in range(n)]
if a == 0 and b == 0 and (c == 0):
	print('No')
	exit()
s1 = 0
s2 = 0
abc = [a, b, c]
moji = ['A', 'B', 'C']

def checkmoji(s):
	if s == 'AB':
		s1 = 0
		s2 = 1
	elif s == 'AC':
		s1 = 0
		s2 = 2
	elif s == 'BC':
		s1 = 1
		s2 = 2
	return (s1, s2)
ans = []
for i in range(n):
	(s1, s2) = checkmoji(si[i])
	if abc[s1] == 0 and abc[s2] == 0:
		print('No')
		exit()
	if abc[s2] == 0:
		abc[s1] -= 1
		abc[s2] += 1
		ans.append(moji[s2])
	elif abc[s1] == 0:
		abc[s1] += 1
		abc[s2] -= 1
		ans.append(moji[s1])
	else:
		if i == n - 1:
			ans.append(moji[s1])
			break
		(s1_a, s2_a) = checkmoji(si[i + 1])
		if s1 == s1_a or s1 == s2_a:
			abc[s1] += 1
			abc[s2] -= 1
			ans.append(moji[s1])
		else:
			abc[s1] -= 1
			abc[s2] += 1
			ans.append(moji[s2])
print('Yes')
for i in range(len(ans)):
	print(ans[i])


(N, A, B, C) = map(int, input().split())
data = {'A': A, 'B': B, 'C': C}
select = []
S = list((input() for _ in range(N)))
for i in range(N):
	s = S[i]
	if data[s[0]] == data[s[1]] == 0:
		print('No')
		exit(0)
	elif data[s[0]] > data[s[1]]:
		data[s[0]] -= 1
		data[s[1]] += 1
		select.append(s[1])
	elif data[s[0]] < data[s[1]]:
		data[s[0]] += 1
		data[s[1]] -= 1
		select.append(s[0])
	elif i == N - 1:
		select.append(s[0])
	elif s[0] in S[i + 1]:
		data[s[0]] += 1
		data[s[1]] -= 1
		select.append(s[0])
	else:
		data[s[0]] -= 1
		data[s[1]] += 1
		select.append(s[1])
print('Yes')
for i in select:
	print(i)


def operate(S, A, B, C, N):
	OP = []
	for i in range(N):
		if S[i] == 'AB':
			if A == 0 and B == 0:
				return -1
			elif A == 1 and B == 1 and (i < N - 1):
				if S[i + 1] == 'BC':
					OP.append('B')
					(A, B) = (A - 1, B + 1)
				else:
					OP.append('A')
					(A, B) = (A + 1, B - 1)
			elif A >= B:
				OP.append('B')
				(A, B) = (A - 1, B + 1)
			else:
				OP.append('A')
				(A, B) = (A + 1, B - 1)
		if S[i] == 'BC':
			if B == 0 and C == 0:
				return -1
			elif B == 1 and C == 1 and (i < N - 1):
				if S[i + 1] == 'AB':
					OP.append('B')
					(B, C) = (B + 1, C - 1)
				else:
					OP.append('C')
					(B, C) = (B - 1, C + 1)
			elif B >= C:
				OP.append('C')
				(B, C) = (B - 1, C + 1)
			else:
				OP.append('B')
				(B, C) = (B + 1, C - 1)
		if S[i] == 'AC':
			if A == 0 and C == 0:
				return -1
			elif A == 1 and C == 1 and (i < N - 1):
				if S[i + 1] == 'BC':
					OP.append('C')
					(A, C) = (A - 1, C + 1)
				else:
					OP.append('A')
					(A, C) = (A + 1, C - 1)
			elif C >= A:
				OP.append('A')
				(C, A) = (C - 1, A + 1)
			else:
				OP.append('C')
				(C, A) = (C + 1, A - 1)
	return OP

def main():
	(N, A, B, C) = list(map(int, input().split()))
	S = [input() for _ in range(N)]
	ans = operate(S, A, B, C, N)
	if ans != -1:
		print('Yes')
		for i in range(N):
			print(ans[i])
	else:
		print('No')

def __starting_point():
	main()
__starting_point()


(N, A, B, C) = list(map(int, input().split()))
ans = []
flag = True
cnt = 0
while True:
	cnt += 1
	if cnt > N:
		break
	s = input()
	if s == 'AB':
		if A == B == 0:
			flag = False
			break
		elif A == B == 1:
			if cnt == N:
				ans.append('A')
				break
			else:
				cnt += 1
				s = input()
				if s == 'AB':
					ans.append('A')
					ans.append('B')
					continue
				elif s == 'AC':
					ans.append('A')
					ans.append('C')
					B -= 1
					C += 1
					continue
				else:
					ans.append('B')
					ans.append('C')
					A -= 1
					C += 1
					continue
		elif A >= B:
			A -= 1
			B += 1
			ans.append('B')
			continue
		else:
			B -= 1
			A += 1
			ans.append('A')
			continue
	elif s == 'BC':
		if B == C == 0:
			flag = False
			break
		elif B == C == 1:
			if cnt == N:
				ans.append('B')
				break
			else:
				cnt += 1
				s = input()
				if s == 'BC':
					ans.append('B')
					ans.append('C')
					continue
				elif s == 'AB':
					ans.append('B')
					ans.append('A')
					C -= 1
					A += 1
					continue
				else:
					ans.append('C')
					ans.append('A')
					B -= 1
					A += 1
					continue
		elif B >= C:
			B -= 1
			C += 1
			ans.append('C')
			continue
		else:
			C -= 1
			B += 1
			ans.append('B')
			continue
	elif C == A == 0:
		flag = False
		break
	elif C == A == 1:
		if cnt == N:
			ans.append('C')
			break
		else:
			cnt += 1
			s = input()
			if s == 'AC':
				ans.append('C')
				ans.append('A')
				continue
			elif s == 'BC':
				ans.append('C')
				ans.append('B')
				A -= 1
				B += 1
				continue
			else:
				ans.append('A')
				ans.append('B')
				C -= 1
				B += 1
				continue
	elif A >= C:
		A -= 1
		C += 1
		ans.append('C')
		continue
	else:
		C -= 1
		A += 1
		ans.append('A')
		continue
if flag:
	print('Yes')
	for item in ans:
		print(item)
else:
	print('No')


(N, A, B, C) = map(int, input().split())
n = [A, B, C]
c = ['A', 'B', 'C']
S = [input() for i in range(N)]
op = []
for i in range(N):
	if S[i] == 'AB':
		op.append((0, 1))
	elif S[i] == 'BC':
		op.append((1, 2))
	else:
		op.append((2, 0))
dec = []
for i in range(N):
	j1 = op[i][0]
	j2 = op[i][1]
	if n[j1] < n[j2]:
		dec.append(c[j1])
		n[j1] += 1
		n[j2] -= 1
	elif n[j2] < n[j1]:
		dec.append(c[j2])
		n[j2] += 1
		n[j1] -= 1
	elif i < N - 1:
		if j1 in op[i + 1]:
			if j1 == op[i + 1][0]:
				j3 = op[i + 1][1]
			else:
				j3 = op[i + 1][0]
			if n[j3] < n[j1]:
				dec.append(c[j1])
				n[j1] += 1
				n[j2] -= 1
			else:
				dec.append(c[j2])
				n[j2] += 1
				n[j1] -= 1
		else:
			if j2 == op[i + 1][0]:
				j3 = op[i + 1][1]
			else:
				j3 = op[i + 1][0]
			if n[j3] < n[j2]:
				dec.append(c[j2])
				n[j2] += 1
				n[j1] -= 1
			else:
				dec.append(c[j1])
				n[j1] += 1
				n[j2] -= 1
	else:
		dec.append(c[j1])
		n[j1] += 1
		n[j2] -= 1
	if n[0] < 0 or n[1] < 0 or n[2] < 0:
		print('No')
		exit()
print('Yes')
print('\n'.join(dec))


import sys
from collections import Counter as cc
(N, A, B, C) = list(map(int, input().split()))
abc = []
ans = []
for i in range(N):
	abc.append(input())
abc.append('')
a = abc.count('AB') + abc.count('AC')
b = abc.count('AB') + abc.count('BC')
c = abc.count('AC') + abc.count('BC')
for (i, (s, ns)) in enumerate(zip(abc, abc[1:])):
	if s == 'AB':
		if A > B or (A == B and i != N - 1 and ('AB' in ns or 'BC' in ns)):
			A -= 1
			B += 1
			ans.append('B')
		else:
			A += 1
			B -= 1
			ans.append('A')
	elif s == 'AC':
		a -= 1
		c -= 1
		if A > C or (A == C and i != N - 1 and ('AC' in ns or 'BC' in ns)):
			A -= 1
			C += 1
			ans.append('C')
		else:
			A += 1
			C -= 1
			ans.append('A')
	else:
		c -= 1
		b -= 1
		if B > C or (B == C and i != N - 1 and ('AC' in ns or 'BC' in ns)):
			C += 1
			B -= 1
			ans.append('C')
		else:
			C -= 1
			B += 1
			ans.append('B')
	if A < 0 or B < 0 or C < 0:
		print('No')
		return
print('Yes')
for i in range(N):
	print(str(ans[i]))


(n, a, b, c) = map(int, input().split())
stage = []
for _ in range(n):
	s = input()
	stage.append(s)
var = [a, b, c]
if var.count(0) == 3:
	print('No')
	exit()
d = {'A': 0, 'B': 1, 'C': 2}
dd = {0: 'A', 1: 'B', 2: 'C'}
ans = []
for i in range(n):
	p = d[stage[i][0]]
	q = d[stage[i][1]]
	r = 3 - p - q
	if var[p] == 0 and var[q] == 0:
		print('No')
		exit()
	elif var[p] == 1 and var[q] == 1 and (var[r] == 0):
		if i != n - 1:
			pp = d[stage[i + 1][0]]
			qq = d[stage[i + 1][1]]
			if p not in [pp, qq]:
				var[q] += 1
				var[p] -= 1
				ans.append(dd[q])
			else:
				var[p] += 1
				var[q] -= 1
				ans.append(dd[p])
		else:
			ans.append(dd[p])
	elif var[p] < var[q]:
		var[p] += 1
		var[q] -= 1
		ans.append(dd[p])
	else:
		var[q] += 1
		var[p] -= 1
		ans.append(dd[q])
print('Yes')
for x in ans:
	print(x)


import sys
readline = sys.stdin.readline
(N, A, B, C) = map(int, readline().split())
val = [A, B, C]
S = [readline().rstrip() for i in range(N)]
ans = []

def get_ind(s):
	res = []
	for c in s:
		if c == 'A':
			res.append(0)
		elif c == 'B':
			res.append(1)
		elif c == 'C':
			res.append(2)
	return res

def get_alpha(x):
	return 'ABC'[x]
for i in range(N):
	(ind_x, ind_y) = get_ind(S[i])
	if val[ind_x] == 0 and val[ind_y] == 0:
		print('No')
		exit(0)
	if val[ind_x] < val[ind_y]:
		ans += [get_alpha(ind_x)]
		val[ind_x] += 1
		val[ind_y] -= 1
	elif val[ind_x] > val[ind_y]:
		ans += [get_alpha(ind_y)]
		val[ind_y] += 1
		val[ind_x] -= 1
	elif i + 1 < N and get_alpha(ind_x) in S[i + 1]:
		ans += [get_alpha(ind_x)]
		val[ind_x] += 1
		val[ind_y] -= 1
	else:
		ans += [get_alpha(ind_y)]
		val[ind_y] += 1
		val[ind_x] -= 1
print('Yes')
for a in ans:
	print(a)


import sys
sys.setrecursionlimit(10 ** 7)
(n, a, b, c) = map(int, input().split())
s = [input() for _ in range(n)]
ans = []
d = {'A': a, 'B': b, 'C': c}

def dfs(i):
	if min(d.values()) < 0:
		return
	if i == n:
		print('Yes')
		print(*ans, sep='\n')
		exit()
	for j in range(2):
		add = s[i][j]
		sub = s[i][1 - j]
		d[add] += 1
		d[sub] -= 1
		ans.append(add)
		dfs(i + 1)
		d[add] -= 1
		d[sub] += 1
		ans.pop()
dfs(0)
print('No')


(n, a, b, c) = map(int, input().split())
s = []
for i in range(n):
	tmp_s = input()
	s.append(tmp_s)
ans = []
for (i, val) in enumerate(s):
	if val == 'AB':
		if a == b == 0:
			print('No')
			exit(0)
		elif a < b or (a == b and i != n - 1 and ('A' in s[i + 1])):
			ans.append('A')
			a += 1
			b -= 1
		else:
			ans.append('B')
			a -= 1
			b += 1
	elif val == 'BC':
		if b == c == 0:
			print('No')
			exit(0)
		elif b < c or (b == c and i != n - 1 and ('B' in s[i + 1])):
			ans.append('B')
			b += 1
			c -= 1
		else:
			ans.append('C')
			b -= 1
			c += 1
	elif c == a == 0:
		print('No')
		exit(0)
	elif c < a or (c == a and i != n - 1 and ('C' in s[i + 1])):
		ans.append('C')
		c += 1
		a -= 1
	else:
		ans.append('A')
		c -= 1
		a += 1
print('Yes')
print(*ans, sep='\n')


(n, a, b, c) = list(map(int, input().split()))
ls = [''] * n
moji = [''] * n
for i in range(n):
	moji[i] = input()
for i in range(n):
	s = moji[i]
	if s == 'AB':
		if a > b:
			a -= 1
			b += 1
			ls[i] = 'B'
		elif a < b or i == n - 1:
			a += 1
			b -= 1
			ls[i] = 'A'
		elif moji[i + 1] == 'AC':
			b -= 1
			a += 1
			ls[i] = 'A'
		else:
			a -= 1
			b += 1
			ls[i] = 'B'
	if s == 'BC':
		if c > b:
			c -= 1
			b += 1
			ls[i] = 'B'
		elif c < b or i == n - 1:
			c += 1
			b -= 1
			ls[i] = 'C'
		elif moji[i + 1] == 'AC':
			b -= 1
			c += 1
			ls[i] = 'C'
		else:
			c -= 1
			b += 1
			ls[i] = 'B'
	if s == 'AC':
		if a > c:
			a -= 1
			c += 1
			ls[i] = 'C'
		elif a < c or n - 1 == i:
			a += 1
			c -= 1
			ls[i] = 'A'
		elif moji[i + 1] == 'AB':
			c -= 1
			a += 1
			ls[i] = 'A'
		else:
			a -= 1
			c += 1
			ls[i] = 'C'
	if a < 0 or b < 0 or c < 0:
		break
if a < 0 or b < 0 or c < 0:
	print('No')
else:
	print('Yes')
	for i in range(n):
		print(ls[i])


import sys
(n, a, b, c) = list(map(int, input().split()))
s = list()
for i in range(n):
	s.append(input())
r = list()
for i in range(n):
	if s[i] == 'AB':
		if a > b:
			r.append('B')
			a = a - 1
			b = b + 1
		elif a < b:
			r.append('A')
			a = a + 1
			b = b - 1
		elif i == n - 1 or 'A' in s[i + 1]:
			r.append('A')
			a = a + 1
			b = b - 1
		else:
			r.append('B')
			a = a - 1
			b = b + 1
	elif s[i] == 'AC':
		if a > c:
			r.append('C')
			a = a - 1
			c = c + 1
		elif a < c:
			r.append('A')
			a = a + 1
			c = c - 1
		elif i == n - 1 or 'A' in s[i + 1]:
			r.append('A')
			a = a + 1
			c = c - 1
		else:
			r.append('C')
			a = a - 1
			c = c + 1
	elif b > c:
		r.append('C')
		b = b - 1
		c = c + 1
	elif b < c:
		r.append('B')
		b = b + 1
		c = c - 1
	elif i == n - 1 or 'B' in s[i + 1]:
		r.append('B')
		b = b + 1
		c = c - 1
	else:
		r.append('C')
		b = b - 1
		c = c + 1
	if min(a, b, c) < 0:
		print('No')
		return
print('Yes')
for str in r:
	print(str)


def main():
	(N, A, B, C) = map(int, input().split())
	s = [''] * (N + 1)
	for i in range(N):
		s[i] = str(input())
	dp = [''] * N
	(a, b, c) = ([0] * (N + 1), [0] * (N + 1), [0] * (N + 1))
	(a[0], b[0], c[0]) = (A, B, C)
	for i in range(N):
		if s[i] == 'AB':
			if a[i] + b[i] == 0:
				print('No')
				return
			elif a[i] == 1 and b[i] == 0:
				a[i + 1] = a[i] - 1
				b[i + 1] = b[i] + 1
				c[i + 1] = c[i]
				dp[i] = 'B'
			elif a[i] == 0 and b[i] == 1:
				a[i + 1] = a[i] + 1
				b[i + 1] = b[i] - 1
				c[i + 1] = c[i]
				dp[i] = 'A'
			elif a[i] == 0 and b[i] > 1:
				a[i + 1] = a[i] + 1
				b[i + 1] = b[i] - 1
				c[i + 1] = c[i]
				dp[i] = 'A'
			elif a[i] > 1 and b[i] == 0:
				a[i + 1] = a[i] - 1
				b[i + 1] = b[i] + 1
				c[i + 1] = c[i]
				dp[i] = 'B'
			elif a[i] == 1 and b[i] == 1:
				if s[i + 1] == '':
					a[i + 1] = a[i] - 1
					b[i + 1] = b[i] + 1
					c[i + 1] = c[i]
					dp[i] = 'B'
				elif s[i + 1] == 'AB':
					a[i + 1] = a[i] + 1
					b[i + 1] = b[i] - 1
					c[i + 1] = c[i]
					dp[i] = 'A'
				elif s[i + 1] == 'BC':
					a[i + 1] = a[i] - 1
					b[i + 1] = b[i] + 1
					c[i + 1] = c[i]
					dp[i] = 'B'
				elif s[i + 1] == 'AC':
					a[i + 1] = a[i] + 1
					b[i + 1] = b[i] - 1
					c[i + 1] = c[i]
					dp[i] = 'A'
			elif a[i] == 1 and b[i] > 1:
				a[i + 1] = a[i] + 1
				b[i + 1] = b[i] - 1
				c[i + 1] = c[i]
				dp[i] = 'A'
			elif a[i] > 1 and b[i] == 1:
				a[i + 1] = a[i] - 1
				b[i + 1] = b[i] + 1
				c[i + 1] = c[i]
				dp[i] = 'B'
			elif a[i] > 1 and b[i] > 1:
				if a[i] >= b[i]:
					a[i + 1] = a[i] - 1
					b[i + 1] = b[i] + 1
					c[i + 1] = c[i]
					dp[i] = 'B'
				elif a[i] < b[i]:
					a[i + 1] = a[i] + 1
					b[i + 1] = b[i] - 1
					c[i + 1] = c[i]
					dp[i] = 'A'
		elif s[i] == 'BC':
			if b[i] + c[i] == 0:
				print('No')
				return
			elif b[i] == 1 and c[i] == 0:
				b[i + 1] = b[i] - 1
				c[i + 1] = c[i] + 1
				a[i + 1] = a[i]
				dp[i] = 'C'
			elif b[i] == 0 and c[i] == 1:
				b[i + 1] = b[i] + 1
				c[i + 1] = c[i] - 1
				a[i + 1] = a[i]
				dp[i] = 'B'
			elif b[i] == 0 and c[i] > 1:
				b[i + 1] = b[i] + 1
				c[i + 1] = c[i] - 1
				a[i + 1] = a[i]
				dp[i] = 'B'
			elif b[i] > 1 and c[i] == 0:
				b[i + 1] = b[i] - 1
				c[i + 1] = c[i] + 1
				a[i + 1] = a[i]
				dp[i] = 'C'
			elif b[i] == 1 and c[i] == 1:
				if s[i + 1] == '':
					b[i + 1] = b[i] - 1
					c[i + 1] = c[i] + 1
					a[i + 1] = a[i]
					dp[i] = 'C'
				elif s[i + 1] == 'BC':
					b[i + 1] = b[i] + 1
					c[i + 1] = c[i] - 1
					a[i + 1] = a[i]
					dp[i] = 'B'
				elif s[i + 1] == 'AC':
					b[i + 1] = b[i] - 1
					c[i + 1] = c[i] + 1
					a[i + 1] = a[i]
					dp[i] = 'C'
				elif s[i + 1] == 'AB':
					b[i + 1] = b[i] + 1
					c[i + 1] = c[i] - 1
					a[i + 1] = a[i]
					dp[i] = 'B'
			elif b[i] == 1 and c[i] > 1:
				b[i + 1] = b[i] + 1
				c[i + 1] = c[i] - 1
				a[i + 1] = a[i]
				dp[i] = 'B'
			elif b[i] > 1 and c[i] == 1:
				b[i + 1] = b[i] - 1
				c[i + 1] = c[i] + 1
				a[i + 1] = a[i]
				dp[i] = 'C'
			elif b[i] > 1 and c[i] > 1:
				if b[i] >= c[i]:
					b[i + 1] = b[i] - 1
					c[i + 1] = c[i] + 1
					a[i + 1] = a[i]
					dp[i] = 'C'
				elif b[i] < c[i]:
					b[i + 1] = b[i] + 1
					c[i + 1] = c[i] - 1
					a[i + 1] = a[i]
					dp[i] = 'B'
		elif s[i] == 'AC':
			if c[i] + a[i] == 0:
				print('No')
				return
			elif c[i] == 1 and a[i] == 0:
				c[i + 1] = c[i] - 1
				a[i + 1] = a[i] + 1
				b[i + 1] = b[i]
				dp[i] = 'A'
			elif c[i] == 0 and a[i] == 1:
				c[i + 1] = c[i] + 1
				a[i + 1] = a[i] - 1
				b[i + 1] = b[i]
				dp[i] = 'C'
			elif c[i] == 0 and a[i] > 1:
				c[i + 1] = c[i] + 1
				a[i + 1] = a[i] - 1
				b[i + 1] = b[i]
				dp[i] = 'C'
			elif c[i] > 1 and a[i] == 0:
				c[i + 1] = c[i] - 1
				a[i + 1] = a[i] + 1
				b[i + 1] = b[i]
				dp[i] = 'A'
			elif c[i] == 1 and a[i] == 1:
				if s[i + 1] == '':
					c[i + 1] = c[i] - 1
					a[i + 1] = a[i] + 1
					b[i + 1] = b[i]
					dp[i] = 'A'
				elif s[i + 1] == 'AC':
					c[i + 1] = c[i] + 1
					a[i + 1] = a[i] - 1
					b[i + 1] = b[i]
					dp[i] = 'C'
				elif s[i + 1] == 'AB':
					c[i + 1] = c[i] - 1
					a[i + 1] = a[i] + 1
					b[i + 1] = b[i]
					dp[i] = 'A'
				elif s[i + 1] == 'BC':
					c[i + 1] = c[i] + 1
					a[i + 1] = a[i] - 1
					b[i + 1] = b[i]
					dp[i] = 'C'
			elif c[i] == 1 and a[i] > 1:
				c[i + 1] = c[i] + 1
				a[i + 1] = a[i] - 1
				b[i + 1] = b[i]
				dp[i] = 'C'
			elif c[i] > 1 and a[i] == 1:
				c[i + 1] = c[i] - 1
				a[i + 1] = a[i] + 1
				b[i + 1] = b[i]
				dp[i] = 'A'
			elif c[i] > 1 and a[i] > 1:
				if c[i] >= a[i]:
					c[i + 1] = c[i] - 1
					a[i + 1] = a[i] + 1
					b[i + 1] = b[i]
					dp[i] = 'A'
				elif c[i] < a[i]:
					c[i + 1] = c[i] + 1
					a[i + 1] = a[i] - 1
					b[i + 1] = b[i]
					dp[i] = 'C'
	print('Yes')
	for v in dp:
		print(v)

def __starting_point():
	main()
__starting_point()


3

def check(s):
	if dict_x[s[0]] == 0 and dict_x[s[1]] == 0:
		return 'NOT'
	elif dict_x[s[0]] > 0 and dict_x[s[1]] == 0:
		return s[1]
	elif dict_x[s[0]] == 0 and dict_x[s[1]] > 0:
		return s[0]
	elif dict_x[s[0]] == 1 and dict_x[s[1]] == 1:
		return 'EVEN'
	elif dict_x[s[0]] > dict_x[s[1]]:
		return s[1]
	else:
		return s[0]

def update(s, mozi):
	if s[1] == mozi:
		dict_x[s[0]] -= 1
		dict_x[s[1]] += 1
	else:
		dict_x[s[0]] += 1
		dict_x[s[1]] -= 1
(n, a, b, c) = map(int, input().split())
dict_x = {'A': a, 'B': b, 'C': c}
s_list = []
ans_list = []
flag = 1
for i in range(0, n):
	s = input()
	s_list.append(s)
if a + b + c == 0:
	flag = 0
elif a + b + c == 1:
	for s in s_list:
		x = check(s)
		if x == 'NOT':
			flag = 0
			break
		else:
			ans_list.append(x)
			update(s, x)
elif a + b + c == 2:
	i = 0
	for s in s_list:
		x = check(s)
		if x == 'NOT':
			flag = 0
			break
		elif x == 'EVEN':
			if i == len(s_list) - 1:
				ans_list.append(s[0])
				update(s, x)
			elif s == s_list[i + 1]:
				ans_list.append(s[0])
				update(s, x)
			elif s[0] in s_list[i + 1]:
				ans_list.append(s[0])
				update(s, s[0])
			else:
				ans_list.append(s[1])
				update(s, s[1])
		else:
			ans_list.append(x)
			update(s, x)
		i += 1
else:
	for s in s_list:
		x = check(s)
		if x == 'NOT':
			flag = 0
			break
		elif x == 'EVEN':
			ans_list.append(s[0])
			update(s, s[0])
		else:
			ans_list.append(x)
			update(s, x)
if flag == 1:
	print('Yes')
	for ans in ans_list:
		print(ans)
else:
	print('No')


from itertools import combinations
(N, A, B, C) = map(int, input().split())
S = [input() for _ in range(N)]

def sol():
	now = {'A': A, 'B': B, 'C': C}
	ret = []
	for (i, s) in enumerate(S):
		(u, v) = (s[0], s[1])
		if now[u] == now[v] == 0:
			return []
		if now[u] > now[v]:
			ret.append(v)
			now[u] -= 1
			now[v] += 1
			continue
		if now[u] < now[v]:
			ret.append(u)
			now[u] += 1
			now[v] -= 1
			continue
		if i == N - 1:
			ret.append(u)
			continue
		nx = S[i + 1]
		if u in nx:
			ret.append(u)
			now[u] += 1
			now[v] -= 1
			continue
		if v in nx:
			ret.append(v)
			now[v] += 1
			now[u] -= 1
			continue
	return ret
ans = sol()
if len(ans) == 0:
	print('No')
	exit()
print('Yes')
print(*ans, sep='\n')


(N, A, B, C) = map(int, input().split())
s = [[ord(i) - ord('A') for i in input()] for _ in range(N)]
L = [A, B, C]
ret = []
for i in range(N):
	(x, y) = s[i]
	done = False
	if L[x] + 1 >= 0 and L[y] - 1 >= 0:
		L[x] += 1
		L[y] -= 1
		if i + 1 != len(s):
			(u, v) = s[i + 1]
			if L[u] + 1 >= 0 and L[v] - 1 >= 0 or (L[u] - 1 >= 0 and L[v] + 1 >= 0):
				done = True
				ret.append(x)
		else:
			done = True
			ret.append(x)
		if not done:
			L[x] -= 1
			L[y] += 1
	if not done and L[x] - 1 >= 0 and (L[y] + 1 >= 0):
		L[x] -= 1
		L[y] += 1
		if i + 1 != len(s):
			(u, v) = s[i + 1]
			if L[u] - 1 >= 0 and L[v] + 1 >= 0 or (L[u] + 1 >= 0 and L[v] - 1 >= 0):
				done = True
				ret.append(y)
		else:
			done = True
			ret.append(y)
		if not done:
			L[x] += 1
			L[y] -= 1
	if not done:
		print('No')
		break
else:
	print('Yes')
	for r in ret:
		print(chr(ord('A') + r))


import sys
(n, a, b, c) = map(int, input().split())
s = []
for _ in range(n):
	s.append(input())
ans = []
for i in range(n):
	if s[i] == 'AB':
		if a == b == 1 and i < n - 1:
			if s[i + 1] == 'AC':
				a += 1
				b -= 1
				ans.append('A')
			else:
				a -= 1
				b += 1
				ans.append('B')
		elif min(a, b) == a:
			a += 1
			b -= 1
			ans.append('A')
		else:
			a -= 1
			b += 1
			ans.append('B')
	elif s[i] == 'BC':
		if c == b == 1 and i < n - 1:
			if s[i + 1] == 'AB':
				b += 1
				c -= 1
				ans.append('B')
			else:
				b -= 1
				c += 1
				ans.append('C')
		elif min(c, b) == b:
			b += 1
			c -= 1
			ans.append('B')
		else:
			b -= 1
			c += 1
			ans.append('C')
	elif c == a == 1 and i < n - 1:
		if s[i + 1] == 'BC':
			c += 1
			a -= 1
			ans.append('C')
		else:
			a += 1
			c -= 1
			ans.append('A')
	elif min(c, a) == c:
		c += 1
		a -= 1
		ans.append('C')
	else:
		c -= 1
		a += 1
		ans.append('A')
	if min(a, b, c) < 0:
		print('No')
		return
print('Yes')
print('\n'.join(ans))


(N, A, B, C) = list(map(int, input().split()))
X = [A, B, C]
ANS = []
flg = True
D = []
pat = {'AB': [0, 1], 'BC': [1, 2], 'AC': [0, 2]}
for i in range(N):
	l = input()
	D.append(pat[l])
for i in range(N):
	(ai, bi) = D[i]
	(an, bn) = D[i + 1] if i < N - 1 else [0, 1]
	if X[ai] == 0 and X[bi] == 0:
		flg = False
		break
	elif X[ai] == 0:
		ANS.append(ai)
		X[ai] += 1
		X[bi] -= 1
	elif X[bi] == 0:
		ANS.append(bi)
		X[bi] += 1
		X[ai] -= 1
	else:
		if ai == an or ai == bn:
			(pl, mi) = (ai, bi)
		else:
			(pl, mi) = (bi, ai)
		ANS.append(pl)
		X[pl] += 1
		X[mi] -= 1
if not flg:
	print('No')
else:
	print('Yes')
	dd = {0: 'A', 1: 'B', 2: 'C'}
	for ans in ANS:
		print(dd[ans])


(N, A, B, C) = map(int, input().split())
X = [input() for _ in range(N)]

def solve(x):
	d = {'A': 0, 'B': 1, 'C': 2}
	ans = []
	for i in range(N):
		(u, v) = X[i]
		if x[d[u]] == x[d[v]] == 0:
			return
		if x[d[u]] < x[d[v]]:
			x[d[u]] += 1
			x[d[v]] -= 1
			ans.append(u)
		elif x[d[u]] > x[d[v]]:
			x[d[u]] -= 1
			x[d[v]] += 1
			ans.append(v)
		elif i < N - 1 and X[i] != X[i + 1]:
			if u in X[i + 1]:
				x[d[u]] += 1
				x[d[v]] -= 1
				ans.append(u)
			else:
				x[d[u]] -= 1
				x[d[v]] += 1
				ans.append(v)
		else:
			x[d[u]] += 1
			x[d[v]] -= 1
			ans.append(u)
		if x[d[u]] < 0 or x[d[v]] < 0:
			return
	return ans
ans = solve([A, B, C])
if ans:
	print('Yes')
	print(*ans, sep='\n')
else:
	print('No')


(n, a, b, c) = map(int, input().split())
s = [input() for _ in range(n)]
d = {'A': a, 'B': b, 'C': c}
ans = ['Yes']
for i in range(n):
	if d[s[i][0]] == 0 and d[s[i][1]] == 0:
		print('No')
		exit()
	if d[s[i][0]] == 1 and d[s[i][1]] == 1 and (n - i > 1):
		d[s[i][0]] = 2
		d[s[i][1]] = 0
		if d[s[i + 1][0]] == 0 and d[s[i + 1][1]] == 0:
			d[s[i][0]] = 0
			d[s[i][1]] = 2
			ans.append(s[i][1])
		else:
			ans.append(s[i][0])
	elif d[s[i][0]] >= d[s[i][1]]:
		d[s[i][0]] = d[s[i][0]] - 1
		d[s[i][1]] = d[s[i][1]] + 1
		ans.append(s[i][1])
	else:
		d[s[i][0]] = d[s[i][0]] + 1
		d[s[i][1]] = d[s[i][1]] - 1
		ans.append(s[i][0])
for i in range(n + 1):
	print(ans[i])


(N, A, B, C) = map(int, input().split())
l = []
i = 0
j = 0
if A + B + C != 2:
	pass
else:
	s = []
	while i < N:
		s.append(input())
		i += 1
	if A == 2 and s[0] == 'BC' or (B == 2 and s[0] == 'AC') or (C == 2 and s[0] == 'AB'):
		print('No')
		return
	print('Yes')
	while j < N:
		if j < N and s[j] == 'AB':
			if A == B == 1:
				if j == N - 1:
					print('A')
					return
				if j < N - 1 and s[j + 1] == 'AB':
					A = 2
					B = 0
					print('A')
				elif s[j + 1] == 'BC':
					A = 0
					B = 1
					C = 1
					print('B\nC')
					j += 1
				else:
					A = 1
					B = 0
					C = 1
					print('A\nC')
					j += 1
			elif A > B:
				print('B')
				A -= 1
				B += 1
			else:
				print('A')
				A += 1
				B -= 1
			j += 1
		if j < N and s[j] == 'BC':
			if B == C == 1:
				if j == N - 1:
					print('B')
					return
				if j < N - 1 and s[j + 1] == 'BC':
					B = 2
					C = 0
					print('B')
				elif s[j + 1] == 'AB':
					A = 1
					B = 1
					C = 0
					print('B\nA')
					j += 1
				else:
					A = 1
					B = 0
					C = 1
					print('C\nA')
					j += 1
			elif B > C:
				print('C')
				B -= 1
				C += 1
			else:
				print('B')
				B += 1
				C -= 1
			j += 1
		if j < N and s[j] == 'AC':
			if A == C == 1:
				if j == N - 1:
					print('A')
					return
				if j < N - 1 and s[j + 1] == 'AC':
					A = 2
					C = 0
					print('A')
				elif s[j + 1] == 'AB':
					A = 1
					B = 1
					C = 0
					print('A\nB')
					j += 1
				else:
					A = 0
					B = 1
					C = 1
					print('C\nB')
					j += 1
			elif A > C:
				print('C')
				A -= 1
				C += 1
			else:
				print('A')
				A += 1
				C -= 1
			j += 1
if A + B + C == 2:
	return
for i in range(N):
	s = input()
	if s == 'AB':
		if A > B:
			A -= 1
			B += 1
			l.append('B')
		else:
			A += 1
			B -= 1
			l.append('A')
	if s == 'BC':
		if B > C:
			B -= 1
			C += 1
			l.append('C')
		else:
			B += 1
			C -= 1
			l.append('B')
	if s == 'AC':
		if C > A:
			C -= 1
			A += 1
			l.append('A')
		else:
			C += 1
			A -= 1
			l.append('C')
	if A < 0 or B < 0 or C < 0:
		print('No')
		return
print('Yes')
print(*l, sep='\n')


(N, A, B, C) = map(int, input().split())
S = [input() for _ in range(N)]
V = {'A': A, 'B': B, 'C': C}
S.append('XX')
op = ''
for i in range(N):
	(s0, s1) = S[i]
	if V[s0] + V[s1] == 0:
		break
	(x, y) = (s0, s1)
	if V[s1] == 0 or (V[s0] != 0 and s1 in S[i + 1]):
		(x, y) = (s1, s0)
	V[x] += 1
	V[y] -= 1
	op += x
if len(op) != N:
	print('No')
else:
	print('Yes')
	[print(x) for x in op]


(N, A, B, C) = list(map(int, input().split()))
d = {}
d['A'] = A
d['B'] = B
d['C'] = C
l = [input() for _ in range(N)]
v = A + B + C

def solve():
	res = []
	if v == 0:
		return []
	elif v == 1:
		for i in l:
			(a, b) = i
			if d[a] == 0 and d[b] == 0:
				return []
			elif d[a] > d[b]:
				d[a] -= 1
				d[b] += 1
				res.append(b)
			else:
				d[a] += 1
				d[b] -= 1
				res.append(a)
	else:
		(a, b) = l[0]
		if d[a] == 0 and d[b] == 0:
			return []
		else:
			for (i, j) in enumerate(l):
				(a, b) = j
				if d[a] > d[b]:
					d[a] -= 1
					d[b] += 1
					res.append(b)
				elif d[a] == d[b] == 1 and i + 1 < N:
					e = set(l[i + 1]) & set([a, b])
					if len(e) == 1:
						f = e.pop()
						g = b if f == a else a
						d[f] += 1
						d[g] -= 1
						res.append(f)
					else:
						d[a] -= 1
						d[b] += 1
						res.append(b)
				else:
					d[a] += 1
					d[b] -= 1
					res.append(a)
	return res
r = solve()
if r:
	print('Yes')
	for i in r:
		print(i)
else:
	print('No')


def main():
	(N, A, B, C) = map(int, input().split())
	values = [A, B, C]
	moves = [input().strip() for _ in range(N)] + ['AB']
	cmds = []
	for (move, next_move) in zip(moves[:-1], moves[1:]):
		if move == 'AB':
			(i, j, lc, rc) = (0, 1, 'A', 'B')
		elif move == 'AC':
			(i, j, lc, rc) = (0, 2, 'A', 'C')
		elif move == 'BC':
			(i, j, lc, rc) = (1, 2, 'B', 'C')
		if next_move == 'AB':
			(ni, nj) = (0, 1)
		elif next_move == 'AC':
			(ni, nj) = (0, 2)
		elif next_move == 'BC':
			(ni, nj) = (1, 2)
		if values[i] == 0 and values[j] == 0:
			cmds = None
			break
		elif values[i] < values[j]:
			cmds.append(lc)
			values[i] += 1
			values[j] -= 1
		elif values[i] > values[j]:
			cmds.append(rc)
			values[i] -= 1
			values[j] += 1
		elif ni == i or nj == i:
			cmds.append(lc)
			values[i] += 1
			values[j] -= 1
		elif ni == j or nj == j:
			cmds.append(rc)
			values[i] -= 1
			values[j] += 1
		else:
			cmds.append(lc)
			values[i] += 1
			values[j] -= 1
	if cmds is not None:
		print('Yes')
		for c in cmds:
			print(c)
	else:
		print('No')
main()


(n, a, b, c) = map(int, input().split())
S = []
for _ in range(n):
	S.append(input())
ans = []
for i in range(n):
	if S[i] == 'AB':
		if a == b == 0:
			print('No')
			exit(0)
		elif a < b or (a == b and i != n - 1 and ('A' in S[i + 1])):
			ans.append('A')
			a += 1
			b -= 1
		else:
			ans.append('B')
			a -= 1
			b += 1
	elif S[i] == 'BC':
		if b == c == 0:
			print('No')
			exit(0)
		elif c < b or (c == b and i != n - 1 and ('C' in S[i + 1])):
			ans.append('C')
			c += 1
			b -= 1
		else:
			ans.append('B')
			c -= 1
			b += 1
	elif c == a == 0:
		print('No')
		exit(0)
	elif c < a or (c == a and i != n - 1 and ('C' in S[i + 1])):
		ans.append('C')
		c += 1
		a -= 1
	else:
		ans.append('A')
		c -= 1
		a += 1
print('Yes')
print('\n'.join(ans))
exit(0)


import random
from collections import deque
import sys
sys.setrecursionlimit(10 ** 7)

def input():
	return sys.stdin.readline().strip()

def get_nums_l():
	return [int(s) for s in input().split(' ')]

def log(*args):
	print('DEBUG:', *args, file=sys.stderr)
(n, a, b, c) = get_nums_l()
d = {'A': a, 'B': b, 'C': c}
S = []
for _ in range(n):
	S.append(input())

def dfs(i, x, history):
	if d[S[i][1 - x]] == 0:
		return False
	d[S[i][x]] += 1
	d[S[i][1 - x]] -= 1
	history.append(S[i][x])
	if i == n - 1:
		return True
	nex = random.randint(0, 1)
	ok = dfs(i + 1, nex, history)
	if ok:
		return ok
	ok = dfs(i + 1, 1 - nex, history)
	if ok:
		return ok
	history.pop()
	d[S[i][x]] -= 1
	d[S[i][1 - x]] += 1
	return False
history = deque()
ok = dfs(0, 0, history) or dfs(0, 1, history)
print('Yes' if ok else 'No')
if ok:
	for s in history:
		print(s)


(n, a, b, c) = [int(x) for x in input().split()]
S = [input() for i in range(n)]
ans = ''
for i in range(n):
	s = S[i]
	if s == 'AB':
		if a == 0 and b == 0:
			print('No')
			exit()
		elif a > b:
			ans += 'B\n'
			a -= 1
			b += 1
		elif b > a:
			ans += 'A\n'
			a += 1
			b -= 1
		elif i + 1 < n and S[i + 1] == 'AC':
			ans += 'A\n'
			a += 1
			b -= 1
		else:
			ans += 'B\n'
			a -= 1
			b += 1
	elif s == 'AC':
		if a == 0 and c == 0:
			print('No')
			exit()
		elif a > c:
			ans += 'C\n'
			a -= 1
			c += 1
		elif c > a:
			ans += 'A\n'
			a += 1
			c -= 1
		elif i + 1 < n and S[i + 1] == 'BC':
			ans += 'C\n'
			a -= 1
			c += 1
		else:
			ans += 'A\n'
			a += 1
			c -= 1
	elif s == 'BC':
		if c == 0 and b == 0:
			print('No')
			exit()
		elif c > b:
			ans += 'B\n'
			c -= 1
			b += 1
		elif b > c:
			ans += 'C\n'
			c += 1
			b -= 1
		elif i + 1 < n and S[i + 1] == 'AB':
			ans += 'B\n'
			b += 1
			c -= 1
		else:
			ans += 'C\n'
			c += 1
			b -= 1
print('Yes')
print(ans, end='')


(N, A, B, C) = map(int, input().split())
li = [A, B, C]
ans = ''
Q = []
for i in range(N):
	Q.append(input())
Q.append(Q[-1])
for i in range(N):
	S = Q[i]
	target = [0, 1, 2]
	ta1 = target[ord(S[0]) - ord('A')]
	ta2 = target[ord(S[1]) - ord('A')]
	if li[ta1] > li[ta2]:
		ans += chr(ord('A') + ta2)
		li[ta1] -= 1
		li[ta2] += 1
	elif li[ta1] < li[ta2]:
		ans += chr(ord('A') + ta1)
		li[ta1] += 1
		li[ta2] -= 1
	elif li[ta1] + li[ta2] >= 4:
		ans += chr(ord('A') + ta2)
		li[ta1] -= 1
		li[ta2] += 1
	elif li[ta1] == 0 and li[ta2] == 0:
		print('No')
		exit()
	elif S[0] in Q[i + 1] and S[1] in Q[i + 1]:
		ans += chr(ord('A') + ta2)
		li[ta1] -= 1
		li[ta2] += 1
	elif S[0] in Q[i + 1]:
		ans += chr(ord('A') + ta1)
		li[ta1] += 1
		li[ta2] -= 1
	else:
		ans += chr(ord('A') + ta2)
		li[ta1] -= 1
		li[ta2] += 1
print('Yes')
for s in ans:
	print(s)


(N, A, B, C) = map(int, input().split())
v = [A, B, C]
s = [-1 for i in range(N)]
for i in range(N):
	t = input()
	if t == 'AB':
		s[i] = 0
	if t == 'BC':
		s[i] = 1
	if t == 'AC':
		s[i] = 2
ans = [-1 for i in range(N)]
OK = True
for i in range(N):
	p = s[i]
	q = (s[i] + 1) % 3
	if v[p] < v[q]:
		ans[i] = p
		v[p] += 1
		v[q] -= 1
	elif v[p] > v[q]:
		ans[i] = q
		v[p] -= 1
		v[q] += 1
	elif v[p] > 0:
		if i == N - 1:
			ans[i] = p
			v[p] += 1
			v[q] -= 1
		elif s[i + 1] == q:
			ans[i] = q
			v[p] -= 1
			v[q] += 1
		else:
			ans[i] = p
			v[p] += 1
			v[q] -= 1
	else:
		OK = False
		break
ch = ['A', 'B', 'C']
if OK:
	print('Yes')
	for i in range(N):
		print(ch[ans[i]])
else:
	print('No')


import sys

def xxx(val, op):
	target = []
	for (i, o) in enumerate(op):
		if sum([val[k] for k in o]) == 0:
			return []
		k0 = o[0]
		k1 = o[1]
		if val[k0] == 0:
			(p, m) = (k0, k1)
		elif val[k1] == 0:
			(p, m) = (k1, k0)
		elif i < len(op) - 1 and k1 in op[i + 1]:
			(p, m) = (k1, k0)
		else:
			(p, m) = (k0, k1)
		val[p] += 1
		val[m] -= 1
		target.append(p)
	return target
(n, a, b, c) = [int(x) for x in input().split()]
op = [sys.stdin.readline().strip() for _ in range(n)]
val = {'A': a, 'B': b, 'C': c}
target = xxx(val, op)
if len(target) == 0:
	print('No')
else:
	print('Yes')
	for t in target:
		print(t)


(n, a, b, c) = list(map(int, input().split()))
s = [input() for _ in range(n)]
ans = []
d = {'A': a, 'B': b, 'C': c}
for i in range(n):
	(x, y) = list(s[i])
	if d[x] == 0 and d[y] == 0:
		print('No')
		return
	elif d[x] == 1 and d[y] == 1 and (i < n - 1):
		if x in s[i + 1]:
			d[x] += 1
			d[y] -= 1
			ans.append(x)
		else:
			d[x] -= 1
			d[y] += 1
			ans.append(y)
	elif set((d[x], d[y])) == set((1, 0)):
		(d[x], d[y]) = (d[y], d[x])
		ans.append(x if d[x] > d[y] else y)
	elif d[x] >= d[y]:
		d[y] += 1
		d[x] -= 1
		ans.append(y)
	else:
		d[y] -= 1
		d[x] += 1
		ans.append(x)
print('Yes')
for ansi in ans:
	print(ansi)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
(n, *abc) = map(int, input().split())
s = [input().rstrip() for _ in range(n)]
cond = {'AB': (0, 1), 'AC': (0, 2), 'BC': (1, 2)}
legend = ('A', 'B', 'C')
ans = []

def dfs(i):
	if -1 in abc:
		return 0
	elif i == n:
		print('Yes')
		print(*ans, sep='\n')
		exit()
	else:
		(idx1, idx2) = cond[s[i]]
		abc[idx1] += 1
		abc[idx2] -= 1
		ans.append(legend[idx1])
		dfs(i + 1)
		ans.pop()
		abc[idx1] -= 1
		abc[idx2] += 1
		abc[idx1] -= 1
		abc[idx2] += 1
		ans.append(legend[idx2])
		dfs(i + 1)
		ans.pop()
		abc[idx1] += 1
		abc[idx2] -= 1
dfs(0)
print('No')


(N, A, B, C) = map(int, input().split())
S = []
d = {'A': A, 'B': B, 'C': C}
for i in range(N):
	S.append(input())
out = []
for i in range(N):
	s = S[i]
	s0 = s[0]
	s1 = s[1]
	if d[s0] == d[s1] == 0:
		print('No')
		break
	elif d[s0] == 0:
		d[s0] += 1
		d[s1] -= 1
		out.append(s0)
	elif d[s1] == 0:
		d[s0] -= 1
		d[s1] += 1
		out.append(s1)
	elif i == N - 1:
		out.append(s0)
	elif s0 in S[i + 1]:
		d[s0] += 1
		d[s1] -= 1
		out.append(s0)
	else:
		d[s0] -= 1
		d[s1] += 1
		out.append(s1)
else:
	print('Yes')
	for o in out:
		print(o)


import math

def main():
	(N, A, B, C) = map(int, input().split())
	s = [input() for _ in range(N)] + ['']
	history = []
	cnt = {'A': A, 'B': B, 'C': C}
	for i in range(N):
		(x, y) = (s[i][0], s[i][1])
		if cnt[x] > cnt[y]:
			cnt[x] -= 1
			cnt[y] += 1
			history.append(y)
		elif cnt[x] < cnt[y]:
			cnt[x] += 1
			cnt[y] -= 1
			history.append(x)
		elif x in s[i + 1]:
			cnt[x] += 1
			cnt[y] -= 1
			history.append(x)
		else:
			cnt[x] -= 1
			cnt[y] += 1
			history.append(y)
		if cnt[x] < 0 or cnt[y] < 0:
			print('No')
			return
	print('Yes')
	for c in history:
		print(c)
main()


(N, A, B, C) = (int(_) for _ in input().split())
status = [A, B, C]
name = ['A', 'B', 'C']
sel_num = {'AB': (0, 1), 'BC': (1, 2), 'AC': (2, 0)}
S = []
for n in range(N):
	S.append(sel_num[input()])
if A + B + C > 2:
	difficult = False
else:
	difficult = True
ret = []
try:
	for i in range(len(S)):
		(a1, a2) = S[i]
		if status[a2] < status[a1]:
			(a1, a2) = (a2, a1)
		if difficult and status[a1] == 1 and (status[a2] == 1) and (i + 1 < len(S)) and (S[i] != S[i + 1]):
			(b1, b2) = S[i + 1]
			if a2 == b1:
				(a1, a2) = (a2, a1)
		ret.append(name[a1])
		status[a1] += 1
		status[a2] -= 1
		assert status[a2] >= 0
except:
	print('No')
	exit(0)
print('Yes')
for r in ret:
	print(r)


import sys
input = sys.stdin.readline
(n, a, b, c) = map(int, input().split())

def d(x):
	if x == 'AB':
		return 0
	elif x == 'BC':
		return 1
	else:
		return 2
L = [d(input().rsplit()[0]) for _ in range(n)]
ABC = [a, b, c]
ans = []
w = 'ABC'
append = ans.append
sha = {1: 1, 3: 2, 2: 0}
for (i, x) in enumerate(L):
	y = (x + 1) % 3
	if ABC[x] == ABC[y] == 0:
		print('No')
		exit()
	elif ABC[x] == ABC[y]:
		if i < n - 1:
			xx = L[i + 1]
			if x == xx:
				append(w[x])
				ABC[x] += 1
				ABC[y] -= 1
			else:
				ss = sha[x ^ xx]
				if x == ss:
					append(w[x])
					ABC[x] += 1
					ABC[y] -= 1
				else:
					append(w[y])
					ABC[x] -= 1
					ABC[y] += 1
		else:
			append(w[x])
	else:
		if ABC[x] > ABC[y]:
			(x, y) = (y, x)
		append(w[x])
		ABC[x] += 1
		ABC[y] -= 1
print('Yes')
print('\n'.join(ans))


(N, A, B, C) = map(int, input().split())
Ss = [input() for _ in range(N)]
ans = []
arr = {}
arr['A'] = A
arr['B'] = B
arr['C'] = C
for (i, s) in enumerate(Ss):
	v1 = s[0]
	v2 = s[1]
	if arr[v1] == arr[v2] == 0:
		print('No')
		exit()
	if i < N - 1 and arr[v1] == arr[v2] == 1:
		if s == Ss[i + 1]:
			ans.append(v1)
			arr[v1] += 1
			arr[v2] -= 1
		elif v1 in Ss[i + 1]:
			ans.append(v1)
			arr[v1] += 1
			arr[v2] -= 1
		else:
			ans.append(v2)
			arr[v1] -= 1
			arr[v2] += 1
	elif arr[v1] < arr[v2]:
		ans.append(v1)
		arr[v1] += 1
		arr[v2] -= 1
	else:
		ans.append(v2)
		arr[v1] -= 1
		arr[v2] += 1
print('Yes')
for a in ans:
	print(a)


import sys

def str_to_int(ch):
	if ch == 'A':
		return 0
	if ch == 'B':
		return 1
	if ch == 'C':
		return 2

def int_to_str(ch):
	if ch == 0:
		return 'A'
	if ch == 1:
		return 'B'
	if ch == 2:
		return 'C'
(N, A, B, C) = list(map(int, input().split()))
ABC = [0, 0, 0]
ABC[0] = A
ABC[1] = B
ABC[2] = C
ops = []
for _ in range(N):
	l = list(map(str_to_int, list(input())))
	ops.append(l)
if sum(ABC) == 0:
	print('No')
	return
ans = []
for (idx, op) in enumerate(ops):
	n0 = ABC[op[0]]
	n1 = ABC[op[1]]
	if n0 == 0 and n1 == 0:
		print('No')
		return
	elif n1 == 0:
		inc = op[1]
		dec = op[0]
	elif n0 == 0:
		inc = op[0]
		dec = op[1]
	elif idx + 1 < len(ops) and op[0] in ops[idx + 1]:
		inc = op[0]
		dec = op[1]
	else:
		inc = op[1]
		dec = op[0]
	ans.append(inc)
	ABC[dec] -= 1
	ABC[inc] += 1
print('Yes')
for i in map(int_to_str, ans):
	print(i)
return


(n, a, b, c) = map(int, input().split())
q = [(0, 1) if s == 'AB' else (1, 2) if s == 'BC' else (0, 2) for s in (input() for _ in range(n))]
ans = []
ch = ('A', 'B', 'C')
d = [a, b, c]
for ((x, y), t) in zip(q, q[1:] + [()]):
	if d[x] + d[y] == 0:
		print('No')
		break
	if d[x] > d[y] or (d[x] * d[y] == 1 and y in t):
		(x, y) = (y, x)
	d[x] += 1
	d[y] -= 1
	ans.append(ch[x])
else:
	print('Yes', *ans, sep='\n')


import sys
readline = sys.stdin.readline

def solve(writer):
	(N, A, B, C) = map(int, input().split())
	variables = {'A': A, 'B': B, 'C': C}
	queries = (list(readline().strip()) for _ in range(N))
	next_q = next(queries)
	for i in range(N):
		(let_1, let_2) = next_q
		next_q = next(queries) if i < N - 1 else ()
		if variables[let_1] == variables[let_2] == 0:
			return False
		if variables[let_1] == variables[let_2] == 1 and let_2 in next_q or variables[let_1] > variables[let_2]:
			(let_1, let_2) = (let_2, let_1)
		variables[let_1] += 1
		variables[let_2] -= 1
		writer.append(let_1)
	return True

def main():
	writer = list()
	ok = solve(writer)
	if ok:
		print('Yes')
		for w in writer:
			print(w)
	else:
		print('No')
main()


import sys
sys.setrecursionlimit(10 ** 7)
ans = ''

def dfs(a, b, c, t):
	nonlocal ans
	if a < 0 or b < 0 or c < 0:
		return False
	if t == N:
		return True
	if s[t] == 'AB':
		if dfs(a - 1, b + 1, c, t + 1):
			ans += 'B'
			return True
		elif dfs(a + 1, b - 1, c, t + 1):
			ans += 'A'
			return True
	if s[t] == 'BC':
		if dfs(a, b - 1, c + 1, t + 1):
			ans += 'C'
			return True
		elif dfs(a, b + 1, c - 1, t + 1):
			ans += 'B'
			return True
	if s[t] == 'AC':
		if dfs(a + 1, b, c - 1, t + 1):
			ans += 'A'
			return True
		if dfs(a - 1, b, c + 1, t + 1):
			ans += 'C'
			return True
	return False
(N, A, B, C) = map(int, input().split())
s = [input() for i in range(N)]
if dfs(A, B, C, 0):
	print('Yes')
	print(*ans[::-1], sep='\n')
else:
	print('No')


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():

	def calc(x, y):
		cnt[x] += 1
		cnt[y] -= 1
		res.append(S[x])
	(n, *cnt) = map(int, input().split())
	S = 'ABC'
	query = []
	for _ in range(n):
		s = input().rstrip()
		a = 0 if s == 'AB' else 0 if s == 'AC' else 1
		b = 1 if s == 'AB' else 2 if s == 'AC' else 2
		query.append((a, b))
	query.append((None, None))
	res = []
	for i in range(n):
		(a, b) = query[i]
		if cnt[a] == cnt[b] == 0:
			print('No')
			return
		elif cnt[a] == 0:
			calc(a, b)
		elif cnt[b] == 0:
			calc(b, a)
		else:
			(next_a, next_b) = query[i + 1]
			if a == next_a or a == next_b:
				calc(a, b)
			else:
				calc(b, a)
	print('Yes')
	print(*res, sep='\n')
resolve()


(N, A, B, C) = map(int, input().split())
dic = {'A': A, 'B': B, 'C': C}
S = [input() for _ in range(N)]

def solve(N, dic, S):
	ans = ['Yes']
	for i in range(N):
		if dic[S[i][0]] > dic[S[i][1]]:
			dic[S[i][0]] -= 1
			dic[S[i][1]] += 1
			ans.append(S[i][1])
		elif dic[S[i][0]] < dic[S[i][1]] or dic[S[i][0]] > 1:
			dic[S[i][1]] -= 1
			dic[S[i][0]] += 1
			ans.append(S[i][0])
		elif dic[S[i][0]] == 0:
			return ['No']
		elif i == N - 1:
			dic[S[i][0]] += 1
			dic[S[i][1]] -= 1
			ans.append(S[i][0])
		elif S[i][0] in S[i + 1]:
			dic[S[i][0]] += 1
			dic[S[i][1]] -= 1
			ans.append(S[i][0])
		else:
			dic[S[i][1]] += 1
			dic[S[i][0]] -= 1
			ans.append(S[i][1])
	return ans
print(*solve(N, dic, S), sep='\n')


(n, a, b, c) = map(int, input().split())
s = [input() for _ in range(n)]
can = 'Yes'
ans = []
val = {'A': a, 'B': b, 'C': c}
if a + b + c == 0:
	can = 'No'
elif a + b + c == 1:
	for ss in s:
		(v1, v2) = (ss[0], ss[1])
		if val[v1] == val[v2] == 0:
			can = 'No'
			break
		(val[v1], val[v2]) = (val[v2], val[v1])
		ans.append(v1) if val[v1] else ans.append(v2)
else:
	for i in range(n):
		(v1, v2) = (s[i][0], s[i][1])
		if val[v1] == val[v2] == 0:
			can = 'No'
			break
		if a + b + c == 2 and val[v1] == val[v2] == 1 and (i != n - 1) and (s[i] != s[i + 1]):
			if v1 in s[i + 1]:
				val[v1] += 1
				val[v2] -= 1
				ans.append(v1)
			else:
				val[v2] += 1
				val[v1] -= 1
				ans.append(v2)
		elif val[v1] < val[v2]:
			val[v1] += 1
			val[v2] -= 1
			ans.append(v1)
		else:
			val[v2] += 1
			val[v1] -= 1
			ans.append(v2)
print(can)
if can == 'Yes':
	print('\n'.join(ans))


import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
(N, A, B, C) = map(int, input().split())
S = [input().strip('\n') for _ in range(N)]
Ans = ['Yes']
Sn = {'A': 0, 'B': 0, 'C': 0}

def dfs(i, a, b, c):
	if i == N:
		if min([a, b, c]) >= 0:
			return True
		else:
			return False
	if min([a, b, c]) < 0:
		return False
	(f, s) = (S[i][0], S[i][1])
	Ans.append(f)
	if f == 'A':
		if s == 'B':
			if dfs(i + 1, a + 1, b - 1, c):
				return True
			else:
				Ans.pop()
		elif dfs(i + 1, a + 1, b, c - 1):
			return True
		else:
			Ans.pop()
	elif f == 'B':
		if dfs(i + 1, a, b + 1, c - 1):
			return True
		else:
			Ans.pop()
	Ans.append(s)
	if f == 'A':
		if s == 'B':
			if dfs(i + 1, a - 1, b + 1, c):
				return True
			else:
				Ans.pop()
		elif dfs(i + 1, a - 1, b, c + 1):
			return True
		else:
			Ans.pop()
	elif f == 'B':
		if dfs(i + 1, a, b - 1, c + 1):
			return True
		else:
			Ans.pop()
	return False

def solve():
	if dfs(0, A, B, C):
		print('\n'.join(map(str, Ans)))
	else:
		print('No')
	return 0
solve()


import sys
sys.setrecursionlimit(10 ** 6)
(n, A, B, C) = map(int, input().split())
s = [[*input()] for _ in range(n)]
a = {'A': A, 'B': B, 'C': C}
ans = ['Yes'] + [0] * n

def dfs(i):
	if i == n:
		print('\n'.join(ans))
		exit()
	for (p, m) in [s[i], s[i][::-1]]:
		if a[m]:
			a[p] += 1
			a[m] -= 1
			ans[i + 1] = p
			dfs(i + 1)
			a[p] -= 1
			a[m] += 1
dfs(0)
print('No')


import sys
input = lambda : sys.stdin.readline().rstrip()
D = {'AB': 2, 'AC': 1, 'BC': 0}
(N, a, b, c) = map(int, input().split())
X = [a, b, c]
S = [D[input()] for _ in range(N)]
ANS = []
if max(X) == 0 or X[S[0] - 1] + X[S[0] - 2] == 0:
	print('No')
	exit()
if sum(X) == 1:
	t = 0 if a else 1 if b else 2
	for s in S:
		if X[s]:
			print('No')
			exit()
		t ^= s ^ 3
		ANS.append(t)
		X[s - 1] ^= 1
		X[s - 2] ^= 1
else:
	for (i, s) in enumerate(S):
		if X[s - 1] > X[s - 2] or (X[s - 1] == X[s - 2] and i < N - 1 and (S[i + 1] == (s - 1) % 3)):
			ANS.append((s - 2) % 3)
			X[s - 1] -= 1
			X[s - 2] += 1
		else:
			ANS.append((s - 1) % 3)
			X[s - 1] += 1
			X[s - 2] -= 1
print('Yes')
print('\n'.join([chr(t + 65) for t in ANS]))


(N, A, B, C) = map(int, input().split())
dt = {'AB': (0, 1), 'AC': (0, 2), 'BC': (1, 2)}
Q = [dt[input()] for _ in range(N)]

class Game:

	def __init__(self, ABC):
		self.ABC = ABC
		self.ds = {0: 'A', 1: 'B', 2: 'C'}
		self.ans = []

	def add_q0(self, q0, q1):
		self.ans.append(self.ds[q0])
		self.ABC[q0] += 1
		self.ABC[q1] -= 1

	def add_q1(self, q0, q1):
		self.ans.append(self.ds[q1])
		self.ABC[q0] -= 1
		self.ABC[q1] += 1

def solve1(ABC):
	G = Game(ABC)
	for (q0, q1) in Q:
		if G.ABC[q0] == G.ABC[q1] == 0:
			print('No')
			return
		elif G.ABC[q0] == 0:
			G.add_q0(q0, q1)
		else:
			G.add_q1(q0, q1)
	print('Yes')
	print(*G.ans, sep='\n')

def solve2(ABC):
	G = Game(ABC)
	for (i, (q0, q1)) in enumerate(Q):
		if G.ABC[q0] == G.ABC[q1] == 0:
			print('No')
			return
		elif G.ABC[q0] == 0:
			G.add_q0(q0, q1)
		elif G.ABC[q1] == 0:
			G.add_q1(q0, q1)
		elif G.ABC[q0] == G.ABC[q1] == 1 and sum(ABC) == 2 and (i < N - 1):
			if q0 in Q[i + 1]:
				G.add_q0(q0, q1)
			else:
				G.add_q1(q0, q1)
		elif G.ABC[q0] <= G.ABC[q1]:
			G.add_q0(q0, q1)
		else:
			G.add_q1(q0, q1)
	print('Yes')
	print(*G.ans, sep='\n')
S = A + B + C
if S == 0:
	print('No')
elif S == 1:
	solve1([A, B, C])
else:
	solve2([A, B, C])


def main():
	import sys

	def input():
		return sys.stdin.readline().rstrip()

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

	def answer(ans):
		print('Yes')
		for a in ans:
			print(a)

	def add_answer(x):
		if s[x[0]] > s[x[1]]:
			s[x[0]] -= 1
			s[x[1]] += 1
			ans.append(abc[x[1]])
		else:
			s[x[0]] += 1
			s[x[1]] -= 1
			ans.append(abc[x[0]])
	(n, *s) = list(map(int, input().split()))
	sl = []
	for _ in range(n):
		sl.append(stoidx(input()))
	abc = 'ABC'
	ans = []
	if sum(s) == 0:
		print('No')
		return
	elif sum(s) == 1:
		for x in sl:
			if s[x[0]] == 0 and s[x[1]] == 0:
				print('No')
				return
			add_answer(x)
	else:
		for (i, x) in enumerate(sl):
			if s[x[0]] == 0 and s[x[1]] == 0:
				print('No')
				return
			if i < n - 1 and s[x[0]] == 1 and (s[x[1]] == 1):
				nx = sl[i + 1]
				if x != nx and sum(s) == 2:
					if x[0] in nx:
						s[x[0]] += 1
						s[x[1]] -= 1
						ans.append(abc[x[0]])
					else:
						s[x[0]] -= 1
						s[x[1]] += 1
						ans.append(abc[x[1]])
					continue
			add_answer(x)
	answer(ans)

def __starting_point():
	main()
__starting_point()


from random import randint
(n, a, b, c) = map(int, input().split())
S = []
for i in range(n):
	s = input()
	S.append(s)
ans = []
for i in range(n):
	c0 = S[i]
	if c0 == 'AB':
		if a == b == 0:
			print('No')
			exit(0)
		elif a < b or (a == b and i != n - 1 and ('A' in S[i + 1])):
			ans.append('A')
			a += 1
			b -= 1
		else:
			ans.append('B')
			a -= 1
			b += 1
	elif c0 == 'BC':
		if c == b == 0:
			print('No')
			exit(0)
		elif c < b or (c == b and i != n - 1 and ('C' in S[i + 1])):
			ans.append('C')
			c += 1
			b -= 1
		else:
			ans.append('B')
			c -= 1
			b += 1
	elif c == a == 0:
		print('No')
		exit(0)
	elif c < a or (c == a and i != n - 1 and ('C' in S[i + 1])):
		ans.append('C')
		c += 1
		a -= 1
	else:
		ans.append('A')
		c -= 1
		a += 1
print('Yes')
print('\n'.join(ans))
exit(0)


import sys
K = list(map(int, input().split()))
N = K[0]
S = sum(K[1:4])
if S == 0:
	print('No')
	sys.exit()
s = input()
out = [0 for _ in range(N)]
for ct in range(N):
	if ct < N - 1:
		s_next = input()
	if s == 'AB':
		i = 1
		j = 2
	elif s == 'BC':
		i = 2
		j = 3
	else:
		i = 1
		j = 3
	if K[i] + K[j] == 0:
		print('No')
		sys.exit()
	elif K[i] > K[j]:
		K[i] -= 1
		K[j] += 1
		log = j
	elif K[i] < K[j]:
		K[i] += 1
		K[j] -= 1
		log = i
	elif K[i] == K[j]:
		if ct == N - 1:
			K[i] += 1
			K[j] -= 1
			log = i
			out[ct] = i
			break
		if s_next == 'AB':
			i_n = 1
			j_n = 2
		elif s_next == 'BC':
			i_n = 2
			j_n = 3
		else:
			i_n = 1
			j_n = 3
		if i_n == i or j_n == i:
			K[i] += 1
			K[j] -= 1
			log = i
		else:
			K[j] += 1
			K[i] -= 1
			log = j
	out[ct] = log
	if ct < N - 1:
		s = s_next
print('Yes')
for o in out:
	print(chr(64 + o))


(n, A, B, C) = map(int, input().split())
s = [list(input()) for _ in range(n)]
cur = dict()
(cur['A'], cur['B'], cur['C']) = (A, B, C)
f = True
ans = []
for (i, ss) in enumerate(s):
	if cur[ss[0]] == 1 and cur[ss[1]] == 1 and (sorted(list(cur.values())) == [0, 1, 1]) and (i < len(s) - 1):
		if ss[0] in s[i + 1]:
			cur[ss[0]] += 1
			cur[ss[1]] -= 1
			ans.append(ss[0])
		elif ss[1] in s[i + 1]:
			cur[ss[1]] += 1
			cur[ss[0]] -= 1
			ans.append(ss[1])
	elif cur[ss[0]] >= cur[ss[1]]:
		cur[ss[0]] -= 1
		cur[ss[1]] += 1
		ans.append(ss[1])
	else:
		cur[ss[0]] += 1
		cur[ss[1]] -= 1
		ans.append(ss[0])
	if -1 in list(cur.values()):
		f = False
		break
if f:
	print('Yes')
	for a in ans:
		print(a)
else:
	print('No')


(n, *abc) = map(int, input().split())
ip = [0] * n
for i in range(n):
	tmp = input()
	if tmp == 'AB':
		ip[i] = [0, 1]
	elif tmp == 'BC':
		ip[i] = [1, 2]
	else:
		ip[i] = [0, 2]
ans = 'Yes'
res = [0] * n
s = sum(abc)
if s == 0:
	ans = 'No'
elif s == 1:
	for i in range(n):
		i1 = ip[i][0]
		i2 = ip[i][1]
		ABC = [abc[i1], abc[i2]]
		if ABC == [0, 0]:
			ans = 'No'
		elif ABC == [0, 1]:
			abc[i1] += 1
			abc[i2] -= 1
			res[i] = i1
		else:
			abc[i1] -= 1
			abc[i2] += 1
			res[i] = i2
else:
	i1 = ip[0][0]
	i2 = ip[0][1]
	if abc[i1] + abc[i2] == 0:
		ans = 'No'
	else:
		for i in range(n):
			i1 = ip[i][0]
			i2 = ip[i][1]
			if abc[i1] * abc[i2] == 0:
				if abc[i1] == 0:
					abc[i1] += 1
					abc[i2] -= 1
					res[i] = i1
				else:
					abc[i1] -= 1
					abc[i2] += 1
					res[i] = i2
			elif i + 1 < n and ip[i + 1] != ip[i]:
				c = list(set(ip[i]) & set(ip[i + 1]))[0]
				if i1 == c:
					abc[i1] += 1
					abc[i2] -= 1
					res[i] = i1
				else:
					abc[i1] -= 1
					abc[i2] += 1
					res[i] = i2
			else:
				abc[i1] += 1
				abc[i2] -= 1
				res[i] = i1
print(ans)
dic = {0: 'A', 1: 'B', 2: 'C'}
if ans == 'Yes':
	for i in range(n):
		print(dic[res[i]])


def main():
	(n, a, b, c) = map(int, input().split())
	s = [list(input()) for _ in range(n)]
	num = dict(A=a, B=b, C=c)
	t = a + b + c
	ans = []
	if t == 0:
		print('No')
		return
	if t == 1:
		for i in range(n):
			si = s[i]
			if num[si[0]] == 1:
				num[si[0]] -= 1
				num[si[1]] += 1
				ans.append(si[1])
			elif num[si[1]] == 1:
				num[si[0]] += 1
				num[si[1]] -= 1
				ans.append(si[0])
			else:
				print('No')
				return
		print('Yes')
		print('\n'.join(ans))
		return
	for i in range(n - 1):
		si = s[i]
		if num[si[0]] == 0 and num[si[1]] >= 1:
			num[si[0]] += 1
			num[si[1]] -= 1
			ans.append(si[0])
		elif num[si[1]] == 0 and num[si[0]] >= 1:
			num[si[0]] -= 1
			num[si[1]] += 1
			ans.append(si[1])
		elif num[si[0]] >= 1 and num[si[1]] >= 1:
			sin = s[i + 1]
			if si[0] in sin:
				num[si[0]] += 1
				num[si[1]] -= 1
				ans.append(si[0])
			else:
				num[si[0]] -= 1
				num[si[1]] += 1
				ans.append(si[1])
		else:
			print('No')
			return
	if num[s[n - 1][0]] >= 1:
		ans.append(s[n - 1][1])
	elif num[s[n - 1][1]] >= 1:
		ans.append(s[n - 1][0])
	else:
		print('No')
		return
	print('Yes')
	print('\n'.join(ans))
	return

def __starting_point():
	main()
__starting_point()


(N, A, B, C) = list(map(int, input().split()))
S = [input() for _ in range(N)]
(A, B, C) = (min(A, 2), min(B, 2), min(C, 2))
X = [0, A, B, C]
F = {1: 'A', 2: 'B', 3: 'C'}
ans = []
for (k, s) in enumerate(S):
	if s == 'AB':
		(i, j) = (1, 2)
	elif s == 'BC':
		(i, j) = (2, 3)
	elif s == 'AC':
		(i, j) = (1, 3)
	if X[i] > X[j]:
		X[i] -= 1
		X[j] += 1
		ans.append(j)
	elif X[i] < X[j]:
		X[i] += 1
		X[j] -= 1
		ans.append(i)
	elif X[i] == X[j] == 1 and k < N - 1:
		if S[k + 1][0] == F[i] and S[k + 1][1] == F[i ^ j] or (S[k + 1][0] == F[i ^ j] and S[k + 1][1] == F[i]):
			X[i] += 1
			X[j] -= 1
			ans.append(i)
		else:
			X[j] += 1
			X[i] -= 1
			ans.append(j)
	else:
		X[i] -= 1
		X[j] += 1
		ans.append(j)
	if any([x < 0 for x in X]):
		print('No')
		return
print('Yes')
for a in ans:
	print(F[a])


d = dict()
(n, d['A'], d['B'], d['C']) = map(int, input().split())
s = [input() for i in range(n)]
ans = []
i = 0
while i < n:
	(x, y) = (s[i][0], s[i][1])
	if d[x] == 0 and d[y] == 0:
		print('No')
		quit()
	elif d[x] == 0:
		ans.append(x)
		d[x] += 1
		d[y] -= 1
	elif d[y] == 0:
		ans.append(y)
		d[x] -= 1
		d[y] += 1
	else:
		if i == n - 1:
			ans.append(x)
			break
		if y in s[i + 1]:
			ans.append(y)
			d[x] -= 1
			d[y] += 1
		else:
			ans.append(x)
			d[x] += 1
			d[y] -= 1
	i += 1
print('Yes')
for i in ans:
	print(i)


import sys, math, copy, queue, itertools, bisect, collections
from heapq import *
sys.setrecursionlimit(10 ** 7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10 ** 18
MOD = 10 ** 9 + 7
DD = ((1, 0), (-1, 0), (0, 1), (0, -1))
(n, a, b, c) = LI()
z = [a, b, c]
s = [sys.stdin.readline().rstrip() for _ in range(n)]
ans = []
for i in range(n):
	x = s[i]
	p = -1
	if x == 'AB':
		j = 0
		k = 1
		l = 2
	elif x == 'AC':
		j = 0
		k = 2
		l = 1
	elif x == 'BC':
		j = 1
		k = 2
		l = 0
	if z[j] > z[k]:
		z[j] -= 1
		z[k] += 1
		p = k
	else:
		z[j] += 1
		z[k] -= 1
		p = j
	if (z[j] == 0 or z[k] == 0) and z[l] == 0:
		if i < n - 1:
			y = s[i + 1]
			if y == 'AB':
				j1 = 0
				k1 = 1
				l1 = 2
			elif y == 'AC':
				j1 = 0
				k1 = 2
				l1 = 1
			elif y == 'BC':
				j1 = 1
				k1 = 2
				l1 = 0
			if z[j1] == 0 and z[k1] == 0:
				if z[j] == 0:
					z[j] += 2
					z[k] -= 2
					p = j
				else:
					z[j] -= 2
					z[k] += 2
					p = k
	if min(z) < 0:
		print('No')
		exit(0)
	if p == 0:
		ans.append('A')
	elif p == 1:
		ans.append('B')
	else:
		ans.append('C')
print('Yes')
print(*ans, sep='\n')


(n, a, b, c) = map(int, input().split())
S = [input() for i in range(n)]
A = [a, b, c]
D = {'A': 0, 'B': 1, 'C': 2}
E = ['A', 'B', 'C']
ANS = []
ng = 0
for i in range(n):
	x = D[S[i][0]]
	y = D[S[i][1]]
	if A[x] > A[y]:
		A[x] -= 1
		A[y] += 1
		ANS.append(E[y])
	elif A[y] > A[x]:
		A[y] -= 1
		A[x] += 1
		ANS.append(E[x])
	elif A[x] == 0 and A[y] == 0:
		ng = 1
		break
	elif A[x] == 1 and A[y] == 1 and (i != n - 1):
		xx = D[S[i + 1][0]]
		yy = D[S[i + 1][1]]
		if S[i] != S[i + 1] and (xx == x or yy == x):
			A[x] += 1
			A[y] -= 1
			ANS.append(E[x])
		else:
			A[y] += 1
			A[x] -= 1
			ANS.append(E[y])
	else:
		A[y] += 1
		A[x] -= 1
		ANS.append(E[y])
if ng == 1:
	print('No')
else:
	print('Yes')
	for i in range(len(ANS)):
		print(ANS[i])


(N, A, B, C) = map(int, input().split())
q = [input() for i in range(N)]
d = {'A': A, 'B': B, 'C': C}
ans = []
possible = True
for i in range(N):
	x = q[i][0]
	y = q[i][1]
	z = [s for s in 'ABC' if s != x and s != y][0]
	if d[x] > d[y]:
		ans.append(y)
		d[x] -= 1
		d[y] += 1
	elif d[x] < d[y]:
		ans.append(x)
		d[x] += 1
		d[y] -= 1
	elif d[x] == 1 and d[y] == 1 and (d[z] == 0):
		if i == N - 1 or q[i + 1] == q[i]:
			ans.append(x)
			d[x] += 1
			d[y] -= 1
		elif x in q[i + 1]:
			ans.append(x)
			d[x] += 1
			d[y] -= 1
		else:
			ans.append(y)
			d[y] += 1
			d[x] -= 1
	elif d[x] == 0 and d[y] == 0:
		possible = False
	else:
		ans.append(x)
		d[x] += 1
		d[y] -= 1
if possible:
	print('Yes')
	for i in range(N):
		print(ans[i])
else:
	print('No')


(N, A, B, C) = map(int, input().split())
S = [''] * N
for i in range(N):
	S[i] = input()
play = [''] * N
flag = True
for (i, s) in enumerate(S):
	next = ''
	if i < len(S) - 1:
		next = S[i + 1]
	if s == 'AB':
		if A == 0 and B == 0:
			flag = False
			break
		elif A == B and 'B' in next:
			A -= 1
			B += 1
			play[i] = 'B'
		elif A > B:
			A -= 1
			B += 1
			play[i] = 'B'
		else:
			A += 1
			B -= 1
			play[i] = 'A'
	elif s == 'AC':
		if A == 0 and C == 0:
			flag = False
			break
		elif A == C and 'C' in next:
			A -= 1
			C += 1
			play[i] = 'C'
		elif A > C:
			A -= 1
			C += 1
			play[i] = 'C'
		else:
			A += 1
			C -= 1
			play[i] = 'A'
	elif B == 0 and C == 0:
		flag = False
		break
	elif B == C and 'C' in next:
		B -= 1
		C += 1
		play[i] = 'C'
	elif B > C:
		B -= 1
		C += 1
		play[i] = 'C'
	else:
		B += 1
		C -= 1
		play[i] = 'B'
if flag:
	print('Yes')
	for i in play:
		print(i)
else:
	print('No')


(N, A, B, C) = map(int, input().split())
S = [input() for _ in range(N)]
ans = []
for (i, s) in enumerate(S):
	if s == 'AB':
		if A == 0:
			A += 1
			B -= 1
			ans.append('A')
		elif B == 0:
			A -= 1
			B += 1
			ans.append('B')
		elif i + 1 == N or S[i + 1] == 'AB':
			A += 1
			B -= 1
			ans.append('A')
		elif S[i + 1] == 'BC':
			A -= 1
			B += 1
			ans.append('B')
		else:
			A += 1
			B -= 1
			ans.append('A')
		if A < 0 or B < 0:
			print('No')
			return
	elif s == 'BC':
		if B == 0:
			B += 1
			C -= 1
			ans.append('B')
		elif C == 0:
			B -= 1
			C += 1
			ans.append('C')
		elif i + 1 == N or S[i + 1] == 'BC':
			B += 1
			C -= 1
			ans.append('B')
		elif S[i + 1] == 'AB':
			B += 1
			C -= 1
			ans.append('B')
		else:
			B -= 1
			C += 1
			ans.append('C')
		if B < 0 or C < 0:
			print('No')
			return
	else:
		if C == 0:
			C += 1
			A -= 1
			ans.append('C')
		elif A == 0:
			C -= 1
			A += 1
			ans.append('A')
		elif i + 1 == N or S[i + 1] == 'AC':
			A += 1
			C -= 1
			ans.append('A')
		elif S[i + 1] == 'AB':
			A += 1
			C -= 1
			ans.append('A')
		else:
			A -= 1
			C += 1
			ans.append('C')
		if A < 0 or C < 0:
			print('No')
			return
print('Yes')
for x in ans:
	print(x)


(n, a, b, c) = map(int, input().split())
value_dict = {'A': a, 'B': b, 'C': c}
result_list = []
input_list = []
flag = True
for i in range(n):
	input_list.append(input())
for (next, input) in enumerate(input_list, 1):
	if value_dict[input[0]] < value_dict[input[1]]:
		value_dict[input[0]] += 1
		value_dict[input[1]] -= 1
		result_list.append(input[0])
	elif value_dict[input[1]] < value_dict[input[0]]:
		value_dict[input[1]] += 1
		value_dict[input[0]] -= 1
		result_list.append(input[1])
	elif value_dict[input[0]] == 0:
		flag = False
		break
	elif next == len(input_list):
		result_list.append(input[0])
	elif input[0] in input_list[next]:
		value_dict[input[0]] += 1
		value_dict[input[1]] -= 1
		result_list.append(input[0])
	else:
		value_dict[input[1]] += 1
		value_dict[input[0]] -= 1
		result_list.append(input[1])
if flag:
	print('Yes')
	for result in result_list:
		print(result)
else:
	print('No')


import sys, copy, math, heapq, bisect
from itertools import accumulate
from collections import deque, defaultdict, Counter
sys.setrecursionlimit(500000)
(N, A, B, C) = map(int, input().split())
ABC = [A, B, C]
S = []
SS = ('A', 'B', 'C')
d = [0, 0, 0]
flag = True
for i in range(N):
	s = input()
	if s == 'AB':
		S.append(2)
		d[0] += 1
		d[1] += 1
	elif s == 'BC':
		S.append(0)
		d[1] += 1
		d[2] += 1
	else:
		S.append(1)
		d[2] += 1
		d[0] += 1
ans = []
for i in range(N):
	(x, y) = ((S[i] + 1) % 3, (S[i] + 2) % 3)
	if ABC[x] < ABC[y]:
		ans.append(SS[x])
		ABC[y] -= 1
		ABC[x] += 1
	elif ABC[x] > ABC[y]:
		ans.append(SS[y])
		ABC[y] += 1
		ABC[x] -= 1
	elif i < N - 1:
		if S[i + 1] == y:
			ans.append(SS[x])
			ABC[y] -= 1
			ABC[x] += 1
		else:
			ans.append(SS[y])
			ABC[y] += 1
			ABC[x] -= 1
	else:
		ans.append(SS[y])
		ABC[y] += 1
		ABC[x] -= 1
	if ABC[0] < 0 or ABC[1] < 0 or ABC[2] < 0:
		flag = False
		break
if flag:
	print('Yes')
	print(*ans, sep='\n')
else:
	print('No')


(n, a, b, c) = map(int, input().split())
a = min(3, a)
b = min(3, b)
S = [input() for i in range(n)]
X = a + b + c
idx = 0
log = [0] * n
plog = [(a, b)] * (n + 1)
flag = False
while idx != n:
	if idx == 0 and log[0] == 2:
		flag = True
		break
	(a, b) = plog[idx]
	(dx, dy) = (0, 0)
	if S[idx] == 'AB':
		(dx, dy) = (1, -1)
	elif S[idx] == 'BC':
		(dx, dy) = (0, 1)
	else:
		(dx, dy) = (1, 0)
	if log[idx] == 0:
		a += dx
		b += dy
	elif log[idx] == 1:
		a -= dx
		b -= dy
	else:
		log[idx] = 0
		idx -= 1
		log[idx] += 1
		continue
	if a < 0 or b < 0 or X - (a + b) < 0:
		log[idx] += 1
		continue
	else:
		idx += 1
		plog[idx] = (a, b)
if flag:
	print('No')
else:
	print('Yes')
	for (i, s) in zip(log, S):
		print(s[i])


from heapq import heappush, heappop
(N, A, B, C) = [int(x) for x in input().split()]
S = [input() for i in range(N)]
sToIndex = {'AB': (0, 1), 'AC': (0, 2), 'BC': (1, 2)}
heap = [(0, -min(A, B, C), (A, B, C))]
parent = {}
while heap:
	original = heappop(heap)
	(negT, negMin, state) = original
	if negT == -N:
		print('Yes')
		ans = []
		last = original
		while last in parent:
			nextLast = parent[last]
			diffIndex = None
			for i in range(3):
				if nextLast[2][i] + 1 == last[2][i]:
					diffIndex = i
					break
			ans.append('ABC'[diffIndex])
			last = nextLast
		print('\n'.join(reversed(ans)))
		exit()
	(index1, index2) = sToIndex[S[-negT]]
	nbr1 = list(state)
	nbr1[index1] += 1
	nbr1[index2] -= 1
	min1 = min(nbr1)
	if min1 >= 0:
		node = (negT - 1, -min1, tuple(nbr1))
		if node not in parent:
			heappush(heap, node)
			parent[node] = original
	nbr2 = list(state)
	nbr2[index1] -= 1
	nbr2[index2] += 1
	min2 = min(nbr2)
	if min2 >= 0:
		node = (negT - 1, -min2, tuple(nbr2))
		if node not in parent:
			heappush(heap, node)
			parent[node] = original
print('No')


import sys
sys.setrecursionlimit(1 << 30)
d = 'ABC'
(N, *v) = map(int, input().split())
e = [tuple(map(d.index, input())) for _ in range(N)]
p = []

def f(i):
	if i == len(e):
		print('Yes')
		print('\n'.join(p))
		raise SystemExit
	(k, j) = e[i]
	for (a, s) in ((k, j), (j, k)):
		if v[s] == 0:
			continue
		v[a] += 1
		v[s] -= 1
		p.append(d[a])
		f(i + 1)
		v[a] -= 1
		v[s] += 1
		p.pop()
f(0)
print('No')


(n, a, b, c) = map(int, input().split())
s_ = [input() for i in range(n)]
ans = ''
for i in range(n):
	(s1, s2) = s_[i]
	if s2 == 'B':
		if a == 1 and b == 1 and (i != n - 1):
			if s_[i + 1][0] == 'A':
				(a, b, ans) = (a + 1, b - 1, ans + 'A')
			else:
				(a, b, ans) = (a - 1, b + 1, ans + 'B')
			continue
		(a, b, ans) = (a - 1, b + 1, ans + 'B') if a > b else (a + 1, b - 1, ans + 'A')
		if min(a, b) == -1:
			print('No')
			break
	elif s1 == 'A':
		if a == 1 and c == 1 and (i != n - 1):
			if s_[i + 1][1] == 'C':
				(a, c, ans) = (a - 1, c + 1, ans + 'C')
			else:
				(a, c, ans) = (a + 1, c - 1, ans + 'A')
			continue
		(a, c, ans) = (a - 1, c + 1, ans + 'C') if a > c else (a + 1, c - 1, ans + 'A')
		if min(a, c) == -1:
			print('No')
			break
	else:
		if c == 1 and b == 1 and (i != n - 1):
			if s_[i + 1][1] == 'C':
				(b, c, ans) = (b - 1, c + 1, ans + 'C')
			else:
				(b, c, ans) = (b + 1, c - 1, ans + 'B')
			continue
		(b, c, ans) = (b - 1, c + 1, ans + 'C') if b > c else (b + 1, c - 1, ans + 'B')
		if min(b, c) == -1:
			print('No')
			break
else:
	print('Yes')
	for j in range(n):
		print(ans[j])


(n, *abc) = map(int, input().split())
cond = {'AB': (0, 1), 'AC': (0, 2), 'BC': (1, 2)}
legend = ['A', 'B', 'C']
ans = []
prev_s = ''
for _ in range(n):
	s = input()
	(idx1, idx2) = cond[s]
	if abc[idx1] == abc[idx2] == 0 and ans:
		prev_x = ans.pop()
		if prev_x == prev_s[0]:
			prev_y = prev_s[1]
		else:
			prev_y = prev_s[0]
		ans.append(prev_y)
		abc[legend.index(prev_x)] -= 2
		abc[legend.index(prev_y)] += 2
	if abc[idx1] < abc[idx2]:
		abc[idx1] += 1
		abc[idx2] -= 1
		ans.append(legend[idx1])
	else:
		abc[idx2] += 1
		abc[idx1] -= 1
		ans.append(legend[idx2])
	prev_s = s
	if -1 in abc:
		print('No')
		break
else:
	print('Yes')
	for x in ans:
		print(x)


import sys

def input():
	return sys.stdin.readline()[:-1]

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

def ans(x):
	l = ['A', 'B', 'C']
	return l[x]
(n, a, b, c) = map(int, input().split())
nums = [a, b, c]
s = [input() for _ in range(n)]
res = []
for (i, x) in enumerate(s):
	(y, z) = included(x)
	if nums[y] == nums[z] == 0:
		print('No')
		break
	if i == n - 1:
		if nums[y] >= nums[z]:
			res.append(ans(z))
		elif nums[z] > nums[y]:
			res.append(ans(y))
	elif nums[y] > nums[z]:
		res.append(ans(z))
		nums[y] -= 1
		nums[z] += 1
	elif nums[z] > nums[y]:
		res.append(ans(y))
		nums[z] -= 1
		nums[y] += 1
	elif z in included(s[i + 1]):
		res.append(ans(z))
		nums[y] -= 1
		nums[z] += 1
	else:
		res.append(ans(y))
		nums[z] -= 1
		nums[y] += 1
else:
	print('Yes')
	print(*res, sep='\n')


def select(x, y, ops, i, z):
	if not (x == 1 and y == 1 and (i < len(ops) - 1)):
		if x < y:
			return True
		else:
			return False
	op = ops[i]
	nop = ops[i + 1]
	oo = (op, nop)
	if op == nop:
		return True
	if oo in [('AB', 'AC'), ('BC', 'AB'), ('AC', 'AB')]:
		return True
	return False

def main():
	nabc = [int(_x) for _x in input().split()]
	n = nabc[0]
	a = nabc[1]
	b = nabc[2]
	c = nabc[3]
	ops = []
	for i in range(n):
		ops.append(input())
	result = []
	for i in range(n):
		op = ops[i]
		if op == 'AB':
			if select(a, b, ops, i, c):
				result.append('A')
				a += 1
				b -= 1
			else:
				result.append('B')
				a -= 1
				b += 1
		if op == 'AC':
			if select(a, c, ops, i, b):
				result.append('A')
				a += 1
				c -= 1
			else:
				result.append('C')
				a -= 1
				c += 1
		if op == 'BC':
			if select(b, c, ops, i, a):
				result.append('B')
				b += 1
				c -= 1
			else:
				result.append('C')
				b -= 1
				c += 1
		if a < 0 or b < 0 or c < 0:
			print('No')
			return
	print('Yes')
	for r in result:
		print(r)
main()


import sys
s = []
ans = []

def dfs(a, b, c, i, root):
	if i == n:
		global ans
		ans = root.copy()
		return True
	l = False
	r = False
	if s[i] == 'AB':
		if a > 0:
			root.append('B')
			l = dfs(a - 1, b + 1, c, i + 1, root)
			root.pop()
		if not l and b > 0:
			root.append('A')
			r = dfs(a + 1, b - 1, c, i + 1, root)
			root.pop()
	elif s[i] == 'AC':
		if a > 0:
			root.append('C')
			l = dfs(a - 1, b, c + 1, i + 1, root)
			root.pop()
		if not l and c > 0:
			root.append('A')
			r = dfs(a + 1, b, c - 1, i + 1, root)
			root.pop()
	else:
		if b > 0:
			root.append('C')
			l = dfs(a, b - 1, c + 1, i + 1, root)
			root.pop()
		if not l and c > 0:
			root.append('B')
			r = dfs(a, b + 1, c - 1, i + 1, root)
			root.pop()
	return l or r
sys.setrecursionlimit(10 ** 6)
(n, a, b, c) = map(int, input().split())
s = [''] * n
for i in range(n):
	s[i] = input()
flag = dfs(a, b, c, 0, [])
if flag:
	print('Yes')
	for t in ans:
		print(t)
else:
	print('No')


def update_vrs(vrs, idx, s):
	if idx == 0:
		vrs[s[0]] += 1
		vrs[s[1]] -= 1
	elif idx == 1:
		vrs[s[0]] -= 1
		vrs[s[1]] += 1
	else:
		raise ValueError()

def process1(vrs, lst_s):
	selects = []
	for s in lst_s:
		if vrs[s[0]] == 0 and vrs[s[1]] == 0:
			return (False, None)
		elif vrs[s[0]] == 0:
			selects.append(s[0])
			update_vrs(vrs, 0, s)
		else:
			selects.append(s[1])
			update_vrs(vrs, 1, s)
	return (True, selects)

def process2(vrs, lst_s):
	selects = []
	for (i, s) in enumerate(lst_s):
		if vrs[s[0]] == 0 and vrs[s[1]] == 0:
			return (False, None)
		elif vrs[s[0]] == 0:
			selects.append(s[0])
			update_vrs(vrs, 0, s)
		elif vrs[s[1]] == 0:
			selects.append(s[1])
			update_vrs(vrs, 1, s)
		elif i == len(lst_s) - 1:
			selects.append(s[0])
		else:
			next_s = lst_s[i + 1]
			if s[0] in next_s:
				selects.append(s[0])
				update_vrs(vrs, 0, s)
			else:
				selects.append(s[1])
				update_vrs(vrs, 1, s)
	return (True, selects)

def main():
	vrs = {}
	(n, vrs['A'], vrs['B'], vrs['C']) = [int(v) for v in input().split(' ')]
	lst_s = []
	for _ in range(n):
		lst_s.append(input().strip())
	sum_abc = vrs['A'] + vrs['B'] + vrs['C']
	if sum_abc == 0:
		ans = False
	elif sum_abc == 1:
		(ans, selects) = process1(vrs, lst_s)
	else:
		(ans, selects) = process2(vrs, lst_s)
	if ans is True:
		print('Yes')
		for s in selects:
			print(s)
	else:
		print('No')

def __starting_point():
	main()
__starting_point()


(n, a, b, c) = map(int, input().split())
s = [''] * n
abc = dict()
abc['A'] = a
abc['B'] = b
abc['C'] = c
for i in range(n):
	s[i] = input()
t = [''] * n
yn = ''
for i in range(n):
	if abc[s[i][0]] == abc[s[i][1]] and i < n - 1:
		if s[i][1] in s[i + 1]:
			t[i] = s[i][1]
			abc[s[i][0]] -= 1
			abc[s[i][1]] += 1
			if abc[s[i][0]] < 0:
				yn = 'No'
				break
		else:
			t[i] = s[i][0]
			abc[s[i][0]] += 1
			abc[s[i][1]] -= 1
			if abc[s[i][1]] < 0:
				yn = 'No'
				break
	elif abc[s[i][0]] >= abc[s[i][1]]:
		t[i] = s[i][1]
		abc[s[i][0]] -= 1
		abc[s[i][1]] += 1
		if abc[s[i][0]] < 0:
			yn = 'No'
			break
	else:
		t[i] = s[i][0]
		abc[s[i][0]] += 1
		abc[s[i][1]] -= 1
		if abc[s[i][1]] < 0:
			yn = 'No'
			break
if yn == 'No':
	print('No')
else:
	print('Yes')
	for i in range(n):
		print(t[i])


(N, A, B, C) = map(int, input().split())
if A + B + C == 0:
	print('No')
elif A + B + C == 1:
	ans_list = []
	for _ in range(N):
		com = input()
		if com == 'AB':
			if A == 1:
				A -= 1
				B += 1
				ans_list.append('B')
			elif B == 1:
				A += 1
				B -= 1
				ans_list.append('A')
			else:
				print('No')
				break
		elif com == 'AC':
			if A == 1:
				A -= 1
				C += 1
				ans_list.append('C')
			elif C == 1:
				A += 1
				C -= 1
				ans_list.append('A')
			else:
				print('No')
				break
		elif com == 'BC':
			if B == 1:
				B -= 1
				C += 1
				ans_list.append('C')
			elif C == 1:
				B += 1
				C -= 1
				ans_list.append('B')
			else:
				print('No')
				break
	else:
		print('Yes')
		for ans in ans_list:
			print(ans)
else:
	com_list = []
	for i in range(N):
		com_list.append(input())
	for i in range(N):
		com = com_list[i]
		if com == 'AB':
			if i == 0 and A == 0 and (B == 0):
				print('No')
				break
			elif i == 0:
				print('Yes')
			if i < N - 1 and A + B + C == 2 and (A == 1) and (B == 1) and (com != com_list[i + 1]):
				if com_list[i + 1] == 'AC':
					A += 1
					B -= 1
					print('A')
				elif com_list[i + 1] == 'BC':
					A -= 1
					B += 1
					print('B')
			elif A >= B:
				A -= 1
				B += 1
				print('B')
			else:
				A += 1
				B -= 1
				print('A')
		elif com == 'AC':
			if i == 0 and A == 0 and (C == 0):
				print('No')
				break
			elif i == 0:
				print('Yes')
			if i < N - 1 and A + B + C == 2 and (A == 1) and (C == 1) and (com != com_list[i + 1]):
				if com_list[i + 1] == 'AB':
					A += 1
					C -= 1
					print('A')
				elif com_list[i + 1] == 'BC':
					A -= 1
					C += 1
					print('C')
			elif A >= C:
				A -= 1
				C += 1
				print('C')
			else:
				A += 1
				C -= 1
				print('A')
		elif com == 'BC':
			if i == 0 and B == 0 and (C == 0):
				print('No')
				break
			elif i == 0:
				print('Yes')
			if i < N - 1 and A + B + C == 2 and (B == 1) and (C == 1) and (com != com_list[i + 1]):
				if com_list[i + 1] == 'AB':
					B += 1
					C -= 1
					print('B')
				elif com_list[i + 1] == 'AC':
					B -= 1
					C += 1
					print('C')
			elif B >= C:
				B -= 1
				C += 1
				print('C')
			else:
				B += 1
				C -= 1
				print('B')


(n, a, b, c) = map(int, input().split())
d = {'AB': (0, 1), 'AC': (0, 2), 'BC': (1, 2)}
queries = [d[input()] for _ in range(n)]
history = []
abc = [a, b, c]
for i in range(n):
	(x, y) = queries[i]
	if abc[x] == 0 and abc[y] == 0:
		print('No')
		exit()
	if abc[x] == 1 and abc[y] == 1:
		if i == n - 1:
			history.append('ABC'[x])
			abc[x] += 1
			abc[y] -= 1
		elif x in queries[i + 1]:
			history.append('ABC'[x])
			abc[x] += 1
			abc[y] -= 1
		else:
			history.append('ABC'[y])
			abc[x] -= 1
			abc[y] += 1
	elif abc[x] > abc[y]:
		history.append('ABC'[y])
		abc[x] -= 1
		abc[y] += 1
	else:
		history.append('ABC'[x])
		abc[x] += 1
		abc[y] -= 1
print('Yes')
print('\n'.join(history))


(n, a, b, c) = map(int, input().split())
abc = {'A': a, 'B': b, 'C': c}
s = [input() for _ in range(n)]
ans = []
for i in range(n):
	(s1, s2) = (s[i][0], s[i][1])
	if abc[s1] == abc[s2] == 0:
		print('No')
		exit()
	elif abc[s1] == abc[s2] == 1 and i < n - 1:
		if s[i + 1] == s1 + s2:
			ans += [s1]
			abc[s1] += 1
			abc[s2] -= 1
		elif s1 in s[i + 1]:
			ans += [s1]
			abc[s1] += 1
			abc[s2] -= 1
		else:
			ans += [s2]
			abc[s2] += 1
			abc[s1] -= 1
	elif abc[s1] <= abc[s2]:
		ans += [s1]
		abc[s1] += 1
		abc[s2] -= 1
	else:
		ans += [s2]
		abc[s2] += 1
		abc[s1] -= 1
print('Yes')
for x in ans:
	print(x)


import sys
input = sys.stdin.readline
(n, a, b, c) = map(int, input().split())
count = {'A': a, 'B': b, 'C': c}
queries = []
for _ in range(n):
	query = tuple(input().replace('\n', ''))
	queries.append(query)

def solve(plus, minus):
	count[plus] += 1
	count[minus] -= 1
	ans.append(plus)
ans = []
for (idx, (x, y)) in enumerate(queries):
	if count[x] == count[y] == 0:
		print('No')
		exit()
	if count[x] == count[y] == 1:
		if idx == n - 1:
			solve(x, y)
			break
		nex = queries[idx + 1]
		if x in nex:
			solve(x, y)
		else:
			solve(y, x)
	elif count[x] >= count[y]:
		solve(y, x)
	else:
		solve(x, y)
print('Yes')
for c in ans:
	print(c)


(N, A, B, C) = map(int, input().split())
list_choice = [input() for i in range(N)]
list_choice.append('')

def operation(A, B, C, S, nextS):
	if S == 'AB':
		if max(A, B) == 0:
			return ('No', '', 0, 0, 0)
		elif A < B or (A == 1 and B == 1 and (nextS == 'AC')):
			return ('Yes', 'A', A + 1, B - 1, C)
		else:
			return ('Yes', 'B', A - 1, B + 1, C)
	elif S == 'AC':
		if max(A, C) == 0:
			return ('No', '', 0, 0, 0)
		elif A < C or (A == 1 and C == 1 and (nextS == 'AB')):
			return ('Yes', 'A', A + 1, B, C - 1)
		else:
			return ('Yes', 'C', A - 1, B, C + 1)
	elif max(B, C) == 0:
		return ('No', '', 0, 0, 0)
	elif B < C or (B == 1 and C == 1 and (nextS == 'AB')):
		return ('Yes', 'B', A, B + 1, C - 1)
	else:
		return ('Yes', 'C', A, B - 1, C + 1)

def func(A, B, C, list_choice):
	list_add = []
	for i in range(N):
		(answer, add, A, B, C) = operation(A, B, C, list_choice[i], list_choice[i + 1])
		if answer == 'No':
			return ('No', [])
		else:
			list_add.append(add)
	return ('Yes', list_add)
(answer, list_add) = func(A, B, C, list_choice)
print(answer)
if answer == 'Yes':
	for add in list_add:
		print(add)


import sys
sys.setrecursionlimit(1000000)

def F(S, curr, D, res):
	if D['A'] < 0 or D['B'] < 0 or D['C'] < 0:
		return False
	if len(S) == curr:
		print('Yes')
		for c in res:
			print(c)
		return True
	s = S[curr]
	a = False
	b = False
	if D[s[0]] >= 1:
		D[s[0]] -= 1
		D[s[1]] += 1
		res.append(s[1])
		a = F(S, curr + 1, D, res)
		res.pop(-1)
		D[s[0]] += 1
		D[s[1]] -= 1
	if a:
		return a
	if D[s[1]] >= 1:
		D[s[1]] -= 1
		D[s[0]] += 1
		res.append(s[0])
		b = F(S, curr + 1, D, res)
		res.pop()
		D[s[1]] += 1
		D[s[0]] -= 1
	return a or b
(N, A, B, C) = map(int, input().strip().split())
D = {'A': A, 'B': B, 'C': C}
S = []
res = []
for i in range(N):
	S.append(input())
if not F(S, 0, D, res):
	print('No')


import sys
sys.setrecursionlimit(10 ** 6)
result = []

def calc(a, b, c, i):
	if a < 0 or b < 0 or c < 0:
		return False
	if i >= N:
		return True
	command = s[i]
	if command == 'AB':
		if calc(a + 1, b - 1, c, i + 1):
			result.append('A')
			return True
		if calc(a - 1, b + 1, c, i + 1):
			result.append('B')
			return True
		return False
	elif command == 'AC':
		if calc(a + 1, b, c - 1, i + 1):
			result.append('A')
			return True
		if calc(a - 1, b, c + 1, i + 1):
			result.append('C')
			return True
		return False
	elif command == 'BC':
		if calc(a, b - 1, c + 1, i + 1):
			result.append('C')
			return True
		if calc(a, b + 1, c - 1, i + 1):
			result.append('B')
			return True
		return False

def main():
	global N, s
	(N, A, B, C) = map(int, input().split())
	s = [input() for _ in range(N)]
	if calc(A, B, C, 0):
		print('Yes')
		for c in result[::-1]:
			print(c)
	else:
		print('No')
main()


def solve(A, B, C, S):
	N = len(S)
	abc = [A, B, C]
	path = []
	for si in range(N - 1):
		(i, j) = S[si]
		if abc[i] == abc[j] == 0:
			print('No')
			return
		if abc[i] == 0:
			path.append('ABC'[i])
			abc[i] += 1
			abc[j] -= 1
			continue
		elif abc[j] == 0:
			path.append('ABC'[j])
			abc[j] += 1
			abc[i] -= 1
			continue
		(i2, j2) = S[si + 1]
		if not (abc[j] - 1 == 0 and abc[3 - i - j] == 0 and ({i2, j2} == {3 - i - j, j})):
			path.append('ABC'[i])
			abc[i] += 1
			abc[j] -= 1
			continue
		if not (abc[i] - 1 == 0 and abc[3 - i - j] == 0 and ({i2, j2} == {3 - i - j, i})):
			path.append('ABC'[j])
			abc[j] += 1
			abc[i] -= 1
			continue
		if abc[i] <= abc[j]:
			path.append('ABC'[i])
			abc[i] += 1
			abc[j] -= 1
		else:
			path.append('ABC'[j])
			abc[j] += 1
			abc[i] -= 1
	(i, j) = S[N - 1]
	if abc[i] == abc[j] == 0:
		print('No')
		return
	if abc[i] == 0:
		path.append('ABC'[i])
	else:
		path.append('ABC'[j])
	print('Yes')
	for c in path:
		print(c)
(N, A, B, C) = map(int, input().split())
S = []
for _ in range(N):
	s = input()
	S.append({'AB': (0, 1), 'AC': (0, 2), 'BC': (1, 2)}[s])
solve(A, B, C, S)


(N, A, B, C) = list(map(int, input().split()))
s = [input() for i in range(N)]
u = ['A', 'B', 'C']
ss = ['BC', 'AC', 'AB']
t = [A, B, C]
trace = []
ans = 'Yes'
for i in range(N):
	idx = ss.index(s[i])
	if t[(idx + 1) % 3] == 0 and t[(idx + 2) % 3] == 0:
		ans = 'No'
		break
	elif t[(idx + 2) % 3] == 0:
		t[(idx + 1) % 3] -= 1
		t[(idx + 2) % 3] += 1
		trace.append(u[(idx + 2) % 3])
	elif t[(idx + 1) % 3] == 0:
		t[(idx + 1) % 3] += 1
		t[(idx + 2) % 3] -= 1
		trace.append(u[(idx + 1) % 3])
	elif i + 1 < N and s[i + 1] == ss[(idx + 1) % 3]:
		t[(idx + 1) % 3] -= 1
		t[(idx + 2) % 3] += 1
		trace.append(u[(idx + 2) % 3])
	else:
		t[(idx + 1) % 3] += 1
		t[(idx + 2) % 3] -= 1
		trace.append(u[(idx + 1) % 3])
print(ans)
if ans == 'Yes':
	for v in trace:
		print(v)


import sys
import queue
q = queue.Queue()
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 10
MOD = 10 ** 9 + 7
S = []
history = []
(N, A, B, C) = map(int, input().split())
d = {}
d['A'] = A
d['B'] = B
d['C'] = C
for n in range(N):
	s = input()
	S.append(s)

def select(L, R, x):
	diff = 1
	if L != x:
		diff *= -1
	d[L] += diff
	d[R] -= diff
	history.append(x)
for n in range(N):
	(L, R) = S[n]
	if d[L] >= 2:
		select(L, R, R)
	elif d[L] == 0:
		if d[R] == 0:
			print('No')
			exit()
		else:
			select(L, R, L)
	elif d[L] == 1:
		if d[R] >= 2:
			select(L, R, L)
		elif d[R] == 0:
			select(L, R, R)
		elif d[R] == 1:
			if n != N - 1:
				if L in S[n + 1]:
					select(L, R, L)
				else:
					select(L, R, R)
			else:
				select(L, R, L)
print('Yes')
for h in history:
	print(h)


(n, a, b, c) = map(int, input().split())
nums = {'A': a, 'B': b, 'C': c}
s = []
for i in range(n):
	line = input()
	s.append(line)

def add(a, b):
	nums[a] += 1
	nums[b] -= 1
	ans.append(a)
flag = True
ans = []
for i in range(n):
	a = s[i][0]
	b = s[i][1]
	if nums[a] == 0 and nums[b] == 0:
		print('No')
		flag = False
		break
	if nums[a] == 0:
		add(a, b)
	elif nums[b] == 0:
		add(b, a)
	elif i != n - 1:
		na = s[i + 1][0]
		nb = s[i + 1][1]
		if a == na or a == nb:
			add(a, b)
		else:
			add(b, a)
	else:
		add(a, b)
if flag:
	print('Yes')
	for i in ans:
		print(i)


def func(S, life):
	ans_chr = []
	for i in range(len(S)):
		s = S[i]
		if life[s[0]] > life[s[1]]:
			life[s[0]] -= 1
			life[s[1]] += 1
			ans_chr.append(s[1])
			continue
		elif life[s[0]] < life[s[1]]:
			life[s[1]] -= 1
			life[s[0]] += 1
			ans_chr.append(s[0])
			continue
		elif life[s[0]] == 0 and life[s[1]] == 0:
			return ['No']
		elif i == len(S) - 1:
			ans_chr.append(s[0])
			continue
		elif s[0] in S[i + 1]:
			life[s[1]] -= 1
			life[s[0]] += 1
			ans_chr.append(s[0])
		else:
			life[s[0]] -= 1
			life[s[1]] += 1
			ans_chr.append(s[1])
	return ['Yes', ans_chr]
lst = list(map(int, input().split()))
N = lst[0]
(A, B, C) = lst[1:]
life = {'A': A, 'B': B, 'C': C}
S = []
for i in range(N):
	s = input()
	S.append(s)
ans = func(S, life)
if ans[0] == 'No':
	print('No')
else:
	print('Yes')
	for c in ans[1]:
		print(c)


(n, a, b, c) = map(int, input().split())
v = {'A': a, 'B': b, 'C': c}
ss = []
for _ in range(n):
	ss.append(input())
history = []
flag = True
for i in range(n):
	s = ss[i]
	if v[s[0]] == 0 and v[s[1]] == 0:
		flag = False
		break
	elif v[s[0]] > v[s[1]]:
		history.append(s[1])
		v[s[0]] -= 1
		v[s[1]] += 1
	elif v[s[0]] < v[s[1]]:
		history.append(s[0])
		v[s[0]] += 1
		v[s[1]] -= 1
	elif i == n - 1:
		history.append(s[0])
		v[s[0]] += 1
		v[s[1]] -= 1
	elif s[0] in ss[i + 1]:
		history.append(s[0])
		v[s[0]] += 1
		v[s[1]] -= 1
	else:
		history.append(s[1])
		v[s[0]] -= 1
		v[s[1]] += 1
if flag:
	print('Yes')
	print('\n'.join(history))
else:
	print('No')


def solve():
	ans = []
	for (x, y) in s:
		if num[x] > num[y]:
			(x, y) = (y, x)
		num[x] += 1
		num[y] -= 1
		ans.append(x)
		if num[y] < 0:
			return False
	return ans
from collections import defaultdict
import sys
(n, a, b, c) = map(int, input().split())
num = defaultdict(int)
s = [input() for _ in range(n)]
num['A'] = a
num['B'] = b
num['C'] = c
id = ['A', 'B', 'C']
id.sort(key=lambda x: num[x])
if a + b + c == 0:
	print('No')
	sys.exit()
elif a + b + c == 1:
	ans = solve()
	if ans:
		print('Yes')
		print(*ans, sep='\n')
	else:
		print('No')
elif a + b + c == 2:
	ans = []
	flag = True
	for (i, (x, y)) in enumerate(s):
		if num[x] > num[y]:
			(x, y) = (y, x)
		if num[x] == num[y] and i < n - 1:
			if y == s[i + 1][0] or y == s[i + 1][1]:
				(x, y) = (y, x)
		num[x] += 1
		num[y] -= 1
		ans.append(x)
		if num[y] < 0:
			flag = False
	if flag:
		print('Yes')
		print(*ans, sep='\n')
	else:
		print('No')
elif num[id[0]] == 0 and num[id[1]] == 0 and (s[0] == id[0] + id[1] or s[0] == id[1] + id[0]):
	print('No')
else:
	ans = solve()
	print('Yes')
	print(*ans, sep='\n')


import sys
sys.setrecursionlimit(10 ** 7)
INF = float('inf')
MOD = 10 ** 9 + 7
(N, A, B, C) = map(int, input().split())
num = [A, B, C]
S = []
for i in range(N):
	S.append(input().strip())
S.append('AB')
ans = []
for i in range(N):
	s = S[i]
	s1 = s[0]
	s2 = s[1]
	n1 = num['ABC'.index(s1)]
	n2 = num['ABC'.index(s2)]
	if n1 == n2 == 0:
		print('No')
		exit()
	if n1 == 0:
		num['ABC'.index(s1)] += 1
		num['ABC'.index(s2)] -= 1
		ans.append(s1)
		continue
	if n2 == 0:
		num['ABC'.index(s1)] -= 1
		num['ABC'.index(s2)] += 1
		ans.append(s2)
		continue
	if s1 in S[i + 1]:
		num['ABC'.index(s1)] += 1
		num['ABC'.index(s2)] -= 1
		ans.append(s1)
	else:
		num['ABC'.index(s1)] -= 1
		num['ABC'.index(s2)] += 1
		ans.append(s2)
print('Yes')
for a in ans:
	print(a)


(N, A, B, C) = map(int, input().split())
S = [list(input()) for i in range(N)]
v = [A, B, C]
id_d = {'A': 0, 'B': 1, 'C': 2}
ans = [0] * N
for (i, s) in enumerate(S):
	(s1, s2) = s
	(id1, id2) = (id_d[s1], id_d[s2])
	(v1, v2) = (v[id1], v[id2])
	if v1 == v2 == 0:
		if i == 0:
			print('No')
			quit()
		else:
			(pre_s1, pre_s2) = S[i - 1]
			(pre_id1, pre_id2) = (id_d[pre_s1], id_d[pre_s2])
			if pre_s1 in [s1, s2]:
				v[pre_id1] += 2
				v[pre_id2] -= 2
				ans[i - 1] = pre_s1
				if v[pre_id2] < 0:
					print('No')
					quit()
			else:
				v[pre_id2] += 2
				v[pre_id1] -= 2
				ans[i - 1] = pre_s2
				if v[pre_id1] < 0:
					print('No')
					quit()
	(v1, v2) = (v[id1], v[id2])
	if v1 >= v2:
		ans[i] = s2
		v[id1] -= 1
		v[id2] += 1
	else:
		ans[i] = s1
		v[id1] += 1
		v[id2] -= 1
print('Yes')
print(*ans, sep='\n')


def main():
	(N, A, B, C) = list(map(int, input().split(' ')))
	S = [input() for _ in range(N)]
	D = {'AB': A + B, 'BC': B + C, 'AC': A + C}
	ans = list()
	for (i, s) in enumerate(S):
		if D[s] == 0:
			print('No')
			return
		if s == 'AB':
			if D['BC'] < D['AC'] or (i < N - 1 and S[i + 1] == 'BC' and (D['BC'] == D['AC'] == 1)):
				ans.append('B')
				D['BC'] += 1
				D['AC'] -= 1
			else:
				ans.append('A')
				D['BC'] -= 1
				D['AC'] += 1
		elif s == 'BC':
			if D['AB'] < D['AC'] or (i < N - 1 and S[i + 1] == 'AB' and (D['AB'] == D['AC'] == 1)):
				ans.append('B')
				D['AB'] += 1
				D['AC'] -= 1
			else:
				ans.append('C')
				D['AB'] -= 1
				D['AC'] += 1
		elif D['AB'] < D['BC'] or (i < N - 1 and S[i + 1] == 'AB' and (D['AB'] == D['BC'] == 1)):
			ans.append('A')
			D['AB'] += 1
			D['BC'] -= 1
		else:
			ans.append('C')
			D['AB'] -= 1
			D['BC'] += 1
	print('Yes')
	for a in ans:
		print(a)

def __starting_point():
	main()
__starting_point()


import sys
sys.setrecursionlimit(10 ** 7)
(N, A, B, C) = map(int, input().split())
command = [sorted(list(input())) for _ in range(N)]
ans = []

def game(i, a, b, c, prev):
	if i == N:
		ans.append(prev)
		return True
	(x, y) = command[i]
	if x == 'A' and y == 'B':
		if b:
			bl = game(i + 1, a + 1, b - 1, c, x)
			if bl:
				ans.append(prev)
				return True
		if a:
			bl = game(i + 1, a - 1, b + 1, c, y)
			if bl:
				ans.append(prev)
				return True
	elif x == 'A' and y == 'C':
		if c:
			bl = game(i + 1, a + 1, b, c - 1, x)
			if bl:
				ans.append(prev)
				return True
		if a:
			bl = game(i + 1, a - 1, b, c + 1, y)
			if bl:
				ans.append(prev)
				return True
	else:
		if c:
			bl = game(i + 1, a, b + 1, c - 1, x)
			if bl:
				ans.append(prev)
				return True
		if b:
			bl = game(i + 1, a, b - 1, c + 1, y)
			if bl:
				ans.append(prev)
				return True
	return False
bl = game(0, A, B, C, '?')
if not bl:
	print('No')
else:
	print('Yes')
	ans.pop()
	for x in ans[::-1]:
		print(x)


(N, a, b, c) = map(int, input().split())
S = []
D = [a, b, c]
for _ in range(N):
	S.append(input())
Y = []

def f(s, ns):
	s0 = ord(s[0]) - 65
	s1 = ord(s[1]) - 65
	k = 0
	if D[s0] == D[s1]:
		ns0 = ord(ns[0]) - 65
		ns1 = ord(ns[1]) - 65
		if s0 == ns0 and s1 == ns1:
			k = 0
		elif s0 == 3 - ns0 - ns1:
			k = 0
		else:
			k = 1
	elif D[s0] > D[s1]:
		k = 0
	else:
		k = 1
	if k == 0:
		D[s0] -= 1
		D[s1] += 1
		Y.append(s[1])
	else:
		D[s0] += 1
		D[s1] -= 1
		Y.append(s[0])
g = True
for i in range(N):
	s = S[i]
	if i == N - 1:
		ns = s
	else:
		ns = S[i + 1]
	f(s, ns)
	if D[0] < 0 or D[1] < 0 or D[2] < 0:
		print('No')
		g = False
		break
if g:
	print('Yes')
	for y in Y:
		print(y)


import sys
readline = sys.stdin.readline

def main():
	(N, a, b, c) = map(int, readline().split())
	A = {'A': a, 'B': b, 'C': c}
	S = []
	for i in range(N):
		l = readline().strip()
		S.append([l[0], l[1]])
	ans = ''
	ret = False
	for i in range(N):
		if A[S[i][0]] == 0 and A[S[i][1]] == 0:
			break
		if i == N - 1:
			if A[S[i][0]] > 0:
				ans += S[i][1]
			else:
				ans += S[i][0]
			ret = True
			break
		if A['A'] + A['B'] + A['C'] == 1:
			if A[S[i][0]] == 1:
				if S[i][0] in S[i + 1] and S[i][1] not in S[i + 1]:
					break
				else:
					A[S[i][0]] -= 1
					A[S[i][1]] += 1
					ans += S[i][1]
					continue
			elif S[i][1] in S[i + 1] and S[i][0] not in S[i + 1]:
				break
			else:
				A[S[i][0]] += 1
				A[S[i][1]] -= 1
				ans += S[i][0]
				continue
		if A[S[i][0]] == 0:
			A[S[i][0]] += 1
			A[S[i][1]] -= 1
			ans += S[i][0]
			continue
		elif A[S[i][1]] == 0:
			A[S[i][0]] -= 1
			A[S[i][1]] += 1
			ans += S[i][1]
			continue
		elif S[i][0] in S[i + 1]:
			A[S[i][0]] += 1
			A[S[i][1]] -= 1
			ans += S[i][0]
			continue
		else:
			A[S[i][0]] -= 1
			A[S[i][1]] += 1
			ans += S[i][1]
			continue
	if ret:
		print('Yes')
		for i in range(N):
			print(ans[i])
	else:
		print('No')

def __starting_point():
	main()
__starting_point()


(N, A, B, C) = map(int, input().split())
hashmap = dict()
hashmap = {'A': A, 'B': B, 'C': C}
arr = [int(0) for i in range(N)]
for i in range(N):
	arr[i] = input()
output = []
for i in range(N):
	string = arr[i]
	first = string[0]
	second = string[1]
	if hashmap[first] == 0 and hashmap[second] == 0:
		print('No')
		break
	elif hashmap[first] == 0:
		hashmap[first] += 1
		hashmap[second] -= 1
		output.append(first)
	elif hashmap[second] == 0:
		hashmap[second] += 1
		hashmap[first] -= 1
		output.append(second)
	elif i < N - 1 and first in arr[i + 1]:
		hashmap[first] += 1
		hashmap[second] -= 1
		output.append(first)
	elif i < N - 1 and second in arr[i + 1]:
		hashmap[second] += 1
		hashmap[first] -= 1
		output.append(second)
	else:
		output.append(first)
else:
	print('Yes')
	for i in output:
		print(i)


(n, a, b, c) = map(int, input().split())
variables = [a, b, c]
alph = ['A', 'B', 'C']
s = [[] for _ in range(n)]
for i in range(n):
	(u, v) = map(lambda x: alph.index(x), list(input()))
	s[i] = [u, v]
can_do = True
ans = []
for i in range(n):
	(u, v) = (s[i][0], s[i][1])
	if variables[u] + variables[v] == 0:
		can_do = False
	elif variables[v] == 0:
		variables[u] -= 1
		variables[v] += 1
		ans.append(alph[v])
	elif variables[u] == 0:
		variables[v] -= 1
		variables[u] += 1
		ans.append(alph[u])
	elif i == n - 1:
		variables[u] -= 1
		variables[v] += 1
		ans.append(alph[v])
	elif variables[u] > 0 and variables[v] > 0:
		(next_u, next_v) = (s[i + 1][0], s[i + 1][1])
		if variables[next_u] + variables[next_v] >= 2:
			if variables[u] < variables[v]:
				(u, v) = (v, u)
			variables[u] -= 1
			variables[v] += 1
			ans.append(alph[v])
		else:
			common = list({u, v}.intersection({next_u, next_v}))[0]
			not_common = u + v - common
			variables[common] += 1
			variables[not_common] -= 1
			ans.append(alph[common])
if can_do:
	print('Yes')
	for item in ans:
		print(item)
else:
	print('No')


(n, a, b, c) = map(int, input().split())
q = [input() for i in range(n)]
(ab, ac, bc) = ('AB', 'AC', 'BC')
ans = []
for i in range(n):
	if q[i] == ab and a == b == 0 or (q[i] == ac and a == c == 0) or (q[i] == bc and b == c == 0):
		print('No')
		return
	elif q[i] == ab and [a, b, c] == [1, 1, 0] and (i != n - 1):
		if q[i + 1] == ac:
			(a, b) = (a + 1, b - 1)
			ans.append('A')
		else:
			(a, b) = (a - 1, b + 1)
			ans.append('B')
	elif q[i] == ac and [a, b, c] == [1, 0, 1] and (i != n - 1):
		if q[i + 1] == ab:
			(a, c) = (a + 1, c - 1)
			ans.append('A')
		else:
			(a, c) = (a - 1, c + 1)
			ans.append('C')
	elif q[i] == bc and [a, b, c] == [0, 1, 1] and (i != n - 1):
		if q[i + 1] == ab:
			(b, c) = (b + 1, c - 1)
			ans.append('B')
		else:
			(b, c) = (b - 1, c + 1)
			ans.append('C')
	elif q[i] == ab:
		if a > b:
			(a, b) = (a - 1, b + 1)
			ans.append('B')
		else:
			(a, b) = (a + 1, b - 1)
			ans.append('A')
	elif q[i] == ac:
		if a > c:
			(a, c) = (a - 1, c + 1)
			ans.append('C')
		else:
			(a, c) = (a + 1, c - 1)
			ans.append('A')
	elif q[i] == bc:
		if b > c:
			(b, c) = (b - 1, c + 1)
			ans.append('C')
		else:
			(b, c) = (b + 1, c - 1)
			ans.append('B')
print('Yes')
for i in range(n):
	print(ans[i])


def check(x, y, z, i, ops):
	if x == 1 and y == 1 and (z == 0) and (i < len(ops) - 1):
		return (ops[i], ops[i + 1]) in [('AB', 'AC'), ('BC', 'AB'), ('AC', 'AB')]
	return x <= y
A = 0
B = 1
C = 2
nabc = [int(_x) for _x in input().split()]
n = nabc[0]
abc = nabc[1:]
ops = []
for i in range(n):
	ops.append(input())
result = []
for i in range(n):
	op = ops[i]
	if op == 'AB':
		(s, t, u) = (A, B, C)
	elif op == 'BC':
		(s, t, u) = (B, C, A)
	else:
		(s, t, u) = (A, C, B)
	if check(abc[s], abc[t], abc[u], i, ops):
		result.append(s)
		abc[s] += 1
		abc[t] -= 1
	else:
		result.append(t)
		abc[s] -= 1
		abc[t] += 1
	if abc[s] < 0 or abc[t] < 0:
		print('No')
		break
else:
	print('Yes')
	for r in result:
		if r == A:
			print('A')
		if r == B:
			print('B')
		if r == C:
			print('C')


d = {}
(N, d['A'], d['B'], d['C']) = map(int, input().split())
S = [input() for _ in range(N)]
if sum(d.values()) == 0:
	print('No')
elif sum(d.values()) == 1:
	ans = []
	for s in S:
		if d[s[0]] == d[s[1]] == 0:
			print('No')
			exit()
		elif d[s[0]] > d[s[1]]:
			d[s[0]] -= 1
			d[s[1]] += 1
			ans.append(s[1])
		else:
			d[s[0]] += 1
			d[s[1]] -= 1
			ans.append(s[0])
	print('Yes')
	print(*ans, sep='\n')
else:
	ans = []
	for (i, s) in enumerate(S):
		if d[s[0]] == d[s[1]] == 0:
			print('No')
			exit()
		elif d[s[0]] > d[s[1]]:
			d[s[0]] -= 1
			d[s[1]] += 1
			ans.append(s[1])
		elif d[s[0]] < d[s[1]]:
			d[s[0]] += 1
			d[s[1]] -= 1
			ans.append(s[0])
		elif d[s[0]] == d[s[1]] == 1 and i != N - 1 and (S[i] != S[i + 1]):
			if s[0] in S[i + 1]:
				d[s[0]] += 1
				d[s[1]] -= 1
				ans.append(s[0])
			else:
				d[s[0]] -= 1
				d[s[1]] += 1
				ans.append(s[1])
		else:
			d[s[0]] -= 1
			d[s[1]] += 1
			ans.append(s[1])
	print('Yes')
	print(*ans, sep='\n')


itos = ['A', 'B', 'C']

def swap(ABC, f, t):
	ABC[f] -= 1
	ABC[t] += 1
	return itos[t]

def main():
	(N, A, B, C) = map(int, input().split())
	S = [input() for i in range(N)]
	ABC = [A, B, C]
	StoP = {'AB': (0, 1), 'BC': (1, 2), 'AC': (0, 2)}
	itos = ['A', 'B', 'C']
	L = []
	for i in range(N):
		(x, y) = StoP[S[i]]
		if ABC[x] == 0 and ABC[y] == 0:
			print('No')
			return
		if ABC[x] == 1 and ABC[y] == 1 and (i < N - 1) and (S[i] != S[i + 1]):
			(x2, y2) = StoP[S[i + 1]]
			if x in [x2, y2]:
				L.append(swap(ABC, y, x))
			else:
				L.append(swap(ABC, x, y))
		elif ABC[x] < ABC[y]:
			L.append(swap(ABC, y, x))
		else:
			L.append(swap(ABC, x, y))
	print('Yes')
	print(*L, sep='\n')
main()


Arr = list(map(int, input().split()))
L = []
for i in range(Arr[0]):
	S = input()
	if S == 'AB':
		L.append([1, 2])
	elif S == 'BC':
		L.append([2, 3])
	else:
		L.append([1, 3])
D = {}
D[1] = 'A'
D[2] = 'B'
D[3] = 'C'
if Arr[L[0][0]] + Arr[L[0][1]] == 0:
	print('No')
else:
	ANS = ['Yes']
	for i in range(len(L)):
		if Arr[L[i][0]] == Arr[L[i][1]] and Arr[L[i][0]] == 1:
			if i != len(L) - 1 and L[i] != L[i + 1]:
				if L[i][0] in L[i + 1]:
					ANS.append(D[L[i][0]])
					Arr[L[i][0]] += 1
					Arr[L[i][1]] -= 1
				else:
					ANS.append(D[L[i][1]])
					Arr[L[i][1]] += 1
					Arr[L[i][0]] -= 1
			else:
				ANS.append(D[L[i][0]])
				Arr[L[i][0]] += 1
				Arr[L[i][1]] -= 1
		elif Arr[L[i][0]] + Arr[L[i][1]] == 0:
			print('No')
			exit()
		elif Arr[L[i][0]] >= Arr[L[i][1]]:
			ANS.append(D[L[i][1]])
			Arr[L[i][1]] += 1
			Arr[L[i][0]] -= 1
		else:
			ANS.append(D[L[i][0]])
			Arr[L[i][0]] += 1
			Arr[L[i][1]] -= 1
	for j in range(len(ANS)):
		print(ANS[j])


(N, A, B, C) = map(int, input().split())
s = ['' for i in range(N)]
for i in range(N):
	s[i] = input()
valid = True
ans = []
all_sum = A + B + C
if all_sum >= 3:
	for op in s:
		if op == 'AB':
			if A > B:
				A -= 1
				B += 1
				ans.append('B')
			else:
				A += 1
				B -= 1
				ans.append('A')
		elif op == 'BC':
			if B > C:
				B -= 1
				C += 1
				ans.append('C')
			else:
				B += 1
				C -= 1
				ans.append('B')
		elif A > C:
			A -= 1
			C += 1
			ans.append('C')
		else:
			A += 1
			C -= 1
			ans.append('A')
		if A < 0 or B < 0 or C < 0:
			valid = False
			break
	if valid:
		print('Yes')
		for c in ans:
			print(c)
	else:
		print('No')
else:
	for i in range(N):
		op = s[i]
		if op == 'AB':
			if A > B:
				A -= 1
				B += 1
				ans.append('B')
			elif A < B:
				A += 1
				B -= 1
				ans.append('A')
			elif i != N - 1 and 'A' in s[i + 1]:
				A += 1
				B -= 1
				ans.append('A')
			else:
				A -= 1
				B += 1
				ans.append('B')
		elif op == 'AC':
			if A > C:
				A -= 1
				C += 1
				ans.append('C')
			elif A < C:
				A += 1
				C -= 1
				ans.append('A')
			elif i != N - 1 and 'A' in s[i + 1]:
				A += 1
				C -= 1
				ans.append('A')
			else:
				A -= 1
				C += 1
				ans.append('C')
		elif B > C:
			B -= 1
			C += 1
			ans.append('C')
		elif B < C:
			B += 1
			C -= 1
			ans.append('B')
		elif i != N - 1 and 'B' in s[i + 1]:
			B += 1
			C -= 1
			ans.append('B')
		else:
			B -= 1
			C += 1
			ans.append('C')
		if A < 0 or B < 0 or C < 0:
			valid = False
			break
	if valid:
		print('Yes')
		for c in ans:
			print(c)
	else:
		print('No')


(n, a, b, c) = map(int, input().split())
s = [input() for _ in range(n)]
(AB, BC, AC) = ('AB', 'BC', 'AC')
A = 'A'
B = 'B'
C = 'C'
ans = []
for i in range(n):
	now = s[i]
	if i == n - 1:
		nxt = ' '
	else:
		nxt = s[i + 1]
	if now == AB:
		if a == 0:
			a += 1
			b -= 1
			ans.append(A)
		elif b == 0:
			b += 1
			a -= 1
			ans.append(B)
		elif nxt == BC:
			b += 1
			a -= 1
			ans.append(B)
		else:
			a += 1
			b -= 1
			ans.append(A)
	elif now == BC:
		if b == 0:
			b += 1
			c -= 1
			ans.append(B)
		elif c == 0:
			c += 1
			b -= 1
			ans.append(C)
		elif nxt == AC:
			c += 1
			b -= 1
			ans.append(C)
		else:
			b += 1
			c -= 1
			ans.append(B)
	elif now == AC:
		if a == 0:
			a += 1
			c -= 1
			ans.append(A)
		elif c == 0:
			c += 1
			a -= 1
			ans.append(C)
		elif nxt == BC:
			c += 1
			a -= 1
			ans.append(C)
		else:
			a += 1
			c -= 1
			ans.append(A)
	if min(a, b, c) == -1:
		print('No')
		exit()
print('Yes')
for i in ans:
	print(i)


from collections import deque
from copy import copy
(n, a, b, c) = map(int, input().split())
s = [input().rstrip() for _ in range(n)]
m = {'A': a, 'B': b, 'C': c}
ans = []
for i in range(n):
	if m[s[i][0]] > m[s[i][1]]:
		ans.append(s[i][1])
		m[s[i][0]] -= 1
		m[s[i][1]] += 1
	elif m[s[i][0]] < m[s[i][1]]:
		ans.append(s[i][0])
		m[s[i][0]] += 1
		m[s[i][1]] -= 1
	else:
		if m[s[i][0]] == 0:
			print('No')
			exit()
		if i != n - 1:
			if s[i][0] in s[i + 1]:
				ans.append(s[i][0])
				m[s[i][0]] += 1
				m[s[i][1]] -= 1
			else:
				ans.append(s[i][1])
				m[s[i][0]] -= 1
				m[s[i][1]] += 1
		else:
			ans.append(s[i][0])
print('Yes')
print('\n'.join(ans))


printn = lambda x: print(x, end='')
inn = lambda : int(input())
inl = lambda : list(map(int, input().split()))
inm = lambda : map(int, input().split())
ins = lambda : input().strip()
DBG = True
BIG = 10 ** 18
R = 10 ** 9 + 7

def ddprint(x):
	if DBG:
		print(x)
(n, a, b, c) = inm()
s = []
for i in range(n):
	s.append(ins())
ans = []
for i in range(n):
	if s[i] == 'AB':
		if a == b == 0:
			print('No')
			exit()
		elif a > b or (a == b and i < n - 1 and (s[i + 1] == 'BC')):
			ans.append('B')
			a -= 1
			b += 1
		else:
			ans.append('A')
			b -= 1
			a += 1
	if s[i] == 'AC':
		if a == c == 0:
			print('No')
			exit()
		elif a > c or (a == c and i < n - 1 and (s[i + 1] == 'BC')):
			ans.append('C')
			a -= 1
			c += 1
		else:
			ans.append('A')
			c -= 1
			a += 1
	if s[i] == 'BC':
		if c == b == 0:
			print('No')
			exit()
		elif c > b or (c == b and i < n - 1 and (s[i + 1] == 'AB')):
			ans.append('B')
			c -= 1
			b += 1
		else:
			ans.append('C')
			b -= 1
			c += 1
print('Yes')
for x in ans:
	print(x)


(n, a, b, c) = map(int, input().split())
m = {'A': a, 'B': b, 'C': c}
ss = [input() for _ in range(n)]
ans = []

def _t(s0, s1):
	m[s0] = m[s0] + 1
	m[s1] = m[s1] - 1
	ans.append(s0)
if a + b + c == 0:
	print('No')
	exit(0)
elif a + b + c == 1:
	for (k, v) in m.items():
		if v == 1:
			o = k
	for s in ss:
		if o not in s:
			print('No')
			exit(0)
		o = s.strip(o)
		ans.append(o)
elif a + b + c == 2:
	for (i, s) in enumerate(ss):
		if m[s[0]] + m[s[1]] == 0:
			print('No')
			exit(0)
		if m[s[0]] > m[s[1]]:
			_t(s[1], s[0])
		elif m[s[0]] < m[s[1]]:
			_t(s[0], s[1])
		elif i < len(ss) - 1 and s[0] in ss[i + 1]:
			_t(s[0], s[1])
		else:
			_t(s[1], s[0])
else:
	for s in ss:
		if m[s[0]] + m[s[1]] == 0:
			print('No')
			exit(0)
		if m[s[0]] > m[s[1]]:
			_t(s[1], s[0])
		else:
			_t(s[0], s[1])
print('Yes')
for a in ans:
	print(a)


def main():
	(N, A, B, C) = list(map(int, input().split()))
	S = [{'AB': (0, 1), 'BC': (1, 2), 'AC': (0, 2)}[input()] for _ in range(N)]
	ABC = [A, B, C]
	RR = ['A', 'B', 'C']
	R = []
	for (i, (s1, s2)) in enumerate(S):
		if ABC[s1] == 0 and ABC[s2] == 0:
			return (False, None)
		if ABC[s1] < ABC[s2]:
			(s1, s2) = (s2, s1)
		if A + B + C == 2 and ABC[s1] == 1 and (ABC[s2] == 1) and (i < N - 1) and (S[i] != S[i + 1]):
			(s1n, s2n) = S[i + 1]
			if s1 in [s1n, s2n]:
				(s1, s2) = (s2, s1)
		ABC[s1] -= 1
		ABC[s2] += 1
		R.append(RR[s2])
	return (True, R)
(a, s) = main()
if not a:
	print('No')
else:
	print('Yes')
	print('\n'.join(s))


import sys
(n, a, b, c) = map(int, input().split())
abc = {'A': a, 'B': b, 'C': c}
s = [input() for _ in range(n)]
ans = [None] * n
i = 0
while i < n:
	x = s[i][0]
	y = s[i][1]
	if abc[x] == 0 and abc[y] == 0:
		print('No')
		sys.exit()
	elif abc[x] == 1 and abc[y] == 1 and (i < n - 1):
		if s[i] == s[i + 1]:
			ans[i] = x
			ans[i + 1] = y
			i += 1
		elif x in s[i + 1]:
			ans[i] = x
			abc[x] += 1
			abc[y] -= 1
		else:
			ans[i] = y
			abc[x] -= 1
			abc[y] += 1
	elif abc[x] <= abc[y]:
		ans[i] = x
		abc[x] += 1
		abc[y] -= 1
	else:
		ans[i] = y
		abc[x] -= 1
		abc[y] += 1
	i += 1
print('Yes')
print('\n'.join(ans))


import sys
sys.setrecursionlimit(10 ** 9)
(n, a, b, c) = list(map(int, input().split()))
s = []
for i in range(n):
	s.append(input())
ans = []

def dfs(i, a, b, c):
	if i == n:
		print('Yes')
		for ai in ans:
			print(ai)
		exit()
	si = s[i]
	if si == 'AB':
		if a == 0 and b == 0:
			return
		elif a == 0 and b > 0:
			ans.append('A')
			dfs(i + 1, a + 1, b - 1, c)
		elif a > 0 and b == 0:
			ans.append('B')
			dfs(i + 1, a - 1, b + 1, c)
		else:
			ans.append('A')
			dfs(i + 1, a + 1, b - 1, c)
			ans.pop()
			ans.append('B')
			dfs(i + 1, a - 1, b + 1, c)
	elif si == 'BC':
		if b == 0 and c == 0:
			return
		elif b == 0 and c > 0:
			ans.append('B')
			dfs(i + 1, a, b + 1, c - 1)
		elif b > 0 and c == 0:
			ans.append('C')
			dfs(i + 1, a, b - 1, c + 1)
		else:
			ans.append('B')
			dfs(i + 1, a, b + 1, c - 1)
			ans.pop()
			ans.append('C')
			dfs(i + 1, a, b - 1, c + 1)
	elif c == 0 and a == 0:
		return
	elif c == 0 and a > 0:
		ans.append('C')
		dfs(i + 1, a - 1, b, c + 1)
	elif c > 0 and a == 0:
		ans.append('A')
		dfs(i + 1, a + 1, b, c - 1)
	else:
		ans.append('C')
		dfs(i + 1, a - 1, b, c + 1)
		ans.pop()
		ans.append('A')
		dfs(i + 1, a + 1, b, c - 1)
dfs(0, a, b, c)
print('No')


(n, a, b, c) = map(int, input().split())
s = [input() for i in range(n)]

def decode(c):
	return ord(c) - ord('A')
state = [a, b, c]
choice = []
for i in range(n):
	(j, k) = map(decode, s[i])
	if state[j] == state[k] == 0:
		print('No')
		exit()
	if state[j] > state[k]:
		(j, k) = (k, j)
	if state[j] == state[k] == 1 and i < n - 1:
		(xj, xk) = map(decode, s[i + 1])
		if state[xj] + state[xk] == 1 and k in {xj, xk}:
			(j, k) = (k, j)
	state[j] += 1
	state[k] -= 1
	choice.append('ABC'[j])
print('Yes')
for c in choice:
	print(c)


ABC = [0] * 3
(N, ABC[0], ABC[1], ABC[2]) = map(int, input().split())
s = [''] * N
for i in range(N):
	s[i] = input()
a = ''
b = True
for i in range(N):
	if not ABC[ord(s[i][0]) - ord('A')]:
		if not ABC[ord(s[i][1]) - ord('A')]:
			b = False
			break
		ABC[ord(s[i][0]) - ord('A')] += 1
		ABC[ord(s[i][1]) - ord('A')] -= 1
		a += s[i][0]
	elif not ABC[ord(s[i][1]) - ord('A')]:
		ABC[ord(s[i][0]) - ord('A')] -= 1
		ABC[ord(s[i][1]) - ord('A')] += 1
		a += s[i][1]
	elif i == N - 1:
		ABC[ord(s[i][0]) - ord('A')] += 1
		ABC[ord(s[i][1]) - ord('A')] -= 1
		a += s[i][0]
	elif s[i][0] == s[i + 1][0] or s[i][0] == s[i + 1][1]:
		ABC[ord(s[i][0]) - ord('A')] += 1
		ABC[ord(s[i][1]) - ord('A')] -= 1
		a += s[i][0]
	else:
		ABC[ord(s[i][0]) - ord('A')] -= 1
		ABC[ord(s[i][1]) - ord('A')] += 1
		a += s[i][1]
if b:
	print('Yes')
	for i in a:
		print(i)
else:
	print('No')


(N, *abc) = map(int, input().split())
s = [input() for _ in range(N)]
ans = ['Yes']
for (i, si) in enumerate(s):
	indices = [ord(sii) - 65 for sii in si]
	if sum((abc[ind] for ind in indices)) == 0:
		ans = ['No']
		break
	if min((abc[ind] for ind in indices)) == 0:
		if abc[indices[1]]:
			ans.append(chr(65 + indices[0]))
			abc[indices[0]] += 1
			abc[indices[1]] += -1
		else:
			ans.append(chr(65 + indices[1]))
			abc[indices[1]] += 1
			abc[indices[0]] += -1
	elif i < N - 1 and si != s[i + 1]:
		adding = set(si) & set(s[i + 1])
		if len(adding) == 0:
			adding = si[0]
		else:
			adding = adding.pop()
		ans.append(adding)
		abc[ord(adding) - 65] += 1
		abc[-65 + ord(si[1 - si.index(adding)])] += -1
	else:
		adding = si[0]
		ans.append(adding)
		abc[ord(adding) - 65] += 1
		abc[-65 + ord(si[1 - si.index(adding)])] += -1
print(*ans, sep='\n')
pass


(N, A, B, C) = map(int, input().split())
inputs = tuple((tuple(input()) for _ in range(N)))
dic = {'A': A, 'B': B, 'C': C}
ans = [0] * N
depth = 0
while depth < N:
	(key1, key2) = inputs[depth]
	if dic[key1] < dic[key2]:
		dic[key1] += 1
		dic[key2] -= 1
		ans[depth] = key1
	elif dic[key1] > dic[key2]:
		dic[key2] += 1
		dic[key1] -= 1
		ans[depth] = key2
	elif not dic[key1]:
		break
	elif dic[key1] == 1 and depth + 1 < N:
		(next_key1, next_key2) = inputs[depth + 1]
		(common_key, *_) = {key1, key2} & {next_key1, next_key2}
		(else_key, *_) = {key1, key2} - {common_key}
		dic[common_key] += 1
		dic[else_key] -= 1
		ans[depth] = common_key
	else:
		dic[key1] += 1
		dic[key2] -= 1
		ans[depth] = key1
	depth += 1
else:
	print('Yes')
	print(*ans, sep='\n')
	quit()
print('No')


from sys import stdin
input = stdin.readline
(n, a, b, c) = map(int, input().split())
s = []
f = []
d = dict()
d['A'] = a
d['B'] = b
d['C'] = c
flag = 1
for _ in range(n):
	f.append(input().rstrip())
for x in range(n):
	e = f[x]
	if d[e[0]] == d[e[1]] == 1 and x < n - 1:
		if e[0] in f[x + 1] and e[1] not in f[x + 1]:
			s.append(e[0])
			d[e[1]] -= 1
			d[e[0]] += 1
		else:
			s.append(e[1])
			d[e[0]] -= 1
			d[e[1]] += 1
	elif d[e[0]] >= d[e[1]]:
		s.append(e[1])
		d[e[0]] -= 1
		d[e[1]] += 1
	else:
		s.append(e[0])
		d[e[1]] -= 1
		d[e[0]] += 1
	if d[e[0]] < 0 or d[e[1]] < 0:
		flag = 0
		break
if flag == 0:
	print('No')
else:
	print('Yes')
	print('\n'.join(s))


def main():
	(N, A, B, C) = map(int, input().split())
	variables = {'A': A, 'B': B, 'C': C}
	ans = [None] * N
	S = [None] * N
	for i in range(N):
		S[i] = input()
	for i in range(N):
		(c1, c2) = S[i]
		if variables[c1] == variables[c2] == 0:
			print('No')
			return
		elif variables[c1] == variables[c2] and i + 1 < N:
			if c1 in S[i + 1]:
				ans[i] = c1
				variables[c1] += 1
				variables[c2] -= 1
			else:
				ans[i] = c2
				variables[c1] -= 1
				variables[c2] += 1
		elif variables[c1] > variables[c2]:
			ans[i] = c2
			variables[c1] -= 1
			variables[c2] += 1
		else:
			ans[i] = c1
			variables[c1] += 1
			variables[c2] -= 1
	print('Yes')
	for i in range(N):
		print(ans[i])
main()


(n, a, b, c) = map(int, input().split())
arr = [input() for _ in range(n)]
ans = []
for i in range(n):
	if arr[i] == 'AB':
		if a == 1 and b == 1:
			if i == n - 1 or arr[i + 1] == 'AB' or arr[i + 1] == 'AC':
				a += 1
				b -= 1
				ans.append('A')
			elif arr[i + 1] == 'BC':
				a -= 1
				b += 1
				ans.append('B')
		elif a == 0 and b == 0:
			print('No')
			break
		elif a >= b:
			a -= 1
			b += 1
			ans.append('B')
		else:
			a += 1
			b -= 1
			ans.append('A')
	elif arr[i] == 'AC':
		if a == 1 and c == 1:
			if i == n - 1 or arr[i + 1] == 'AC' or arr[i + 1] == 'AB':
				a += 1
				c -= 1
				ans.append('A')
			elif arr[i + 1] == 'BC':
				a -= 1
				c += 1
				ans.append('C')
		elif a == 0 and c == 0:
			print('No')
			break
		elif a >= c:
			a -= 1
			c += 1
			ans.append('C')
		else:
			a += 1
			c -= 1
			ans.append('A')
	elif arr[i] == 'BC':
		if b == 1 and c == 1:
			if i == n - 1 or arr[i + 1] == 'BC' or arr[i + 1] == 'AB':
				b += 1
				c -= 1
				ans.append('B')
			elif arr[i + 1] == 'AC':
				b -= 1
				c += 1
				ans.append('C')
		elif b == 0 and c == 0:
			print('No')
			break
		elif b >= c:
			b -= 1
			c += 1
			ans.append('C')
		else:
			b += 1
			c -= 1
			ans.append('B')
else:
	print('Yes')
	for i in range(n):
		print(ans[i])


def main():
	import sys
	input = sys.stdin.readline
	(n, *abc) = map(int, input().split())
	query = []
	for _ in [0] * n:
		s = input()
		query.append((ord(s[0]) - ord('A'), ord(s[1]) - ord('A')))
	query.append((0, 1))
	ans = ['A'] * n
	for i in range(n):
		(a, b) = query[i]
		if abc[a] == 0 and abc[b] == 0:
			print('No')
			return
		elif abc[a] == 0:
			abc[a] += 1
			abc[b] -= 1
			ans[i] = chr(ord('A') + a)
		elif abc[b] == 0:
			abc[a] -= 1
			abc[b] += 1
			ans[i] = chr(ord('A') + b)
		elif a in query[i + 1]:
			abc[a] += 1
			abc[b] -= 1
			ans[i] = chr(ord('A') + a)
		else:
			abc[a] -= 1
			abc[b] += 1
			ans[i] = chr(ord('A') + b)
	print('Yes')
	print(*ans, sep='\n')
main()


(n, a, b, c) = map(int, input().split())
column = [a, b, c]
dict_convert = {'A': 0, 'B': 1, 'C': 2}
reverse_convert = {0: 'A', 1: 'B', 2: 'C'}
s = list()
for _ in range(n):
	pair = tuple((dict_convert[val] for val in tuple(input())))
	s.append(pair)
choices = list()

def generate_play():
	for i in range(n):
		if column[s[i][0]] == 0 and column[s[i][1]] == 0:
			return 'No'
		elif column[s[i][0]] == 1 and column[s[i][1]] == 1 and (i < n - 1):
			other_index = next((x for x in range(3) if x not in (s[i][0], s[i][1])))
			if s[i + 1] == (other_index, s[i][0]) or s[i + 1] == (s[i][0], other_index):
				choice = s[i][0]
				column[s[i][1]] -= 1
				column[s[i][0]] += 1
			else:
				choice = s[i][1]
				column[s[i][1]] += 1
				column[s[i][0]] -= 1
			choices.append(choice)
		else:
			if column[s[i][0]] >= column[s[i][1]]:
				choice = s[i][1]
				column[s[i][1]] += 1
				column[s[i][0]] -= 1
			else:
				choice = s[i][0]
				column[s[i][1]] -= 1
				column[s[i][0]] += 1
			choices.append(choice)
	return 'Yes'
ans = generate_play()
print(ans)
if ans == 'Yes':
	[print(reverse_convert[val]) for val in choices]


(n, av, bv, cv) = list(map(int, input().split()))
s = []
for i in range(n):
	s.append(input())
v = {'A': av, 'B': bv, 'C': cv}
selection = []
for i in range(n):
	if v[s[i][0]] == 0:
		selection.append(s[i][0])
		v[s[i][0]] += 1
		v[s[i][1]] -= 1
	elif v[s[i][1]] == 0:
		selection.append(s[i][1])
		v[s[i][0]] -= 1
		v[s[i][1]] += 1
	elif v[s[i][0]] == 1 and v[s[i][1]] == 1:
		if i == n - 1:
			selection.append(s[i][0])
			v[s[i][0]] += 1
			v[s[i][1]] -= 1
		elif s[i + 1][0] == s[i][0] or s[i + 1][1] == s[i][0]:
			selection.append(s[i][0])
			v[s[i][0]] += 1
			v[s[i][1]] -= 1
		else:
			selection.append(s[i][1])
			v[s[i][0]] -= 1
			v[s[i][1]] += 1
	elif v[s[i][0]] > v[s[i][1]]:
		selection.append(s[i][1])
		v[s[i][0]] -= 1
		v[s[i][1]] += 1
	else:
		selection.append(s[i][0])
		v[s[i][0]] += 1
		v[s[i][1]] -= 1
	if v['A'] < 0 or v['B'] < 0 or v['C'] < 0:
		print('No')
		break
else:
	print('Yes')
	for i in range(n):
		print(selection[i])


import sys
(n, a, b, c) = map(int, input().split())
d = {'A': a, 'B': b, 'C': c}
s = []
for _ in range(n):
	s.append(input())
ans = []
for i in range(n):
	if d[s[i][0]] <= 0 and d[s[i][1]] <= 0:
		print('No')
		sys.exit()
	if d[s[i][0]] < d[s[i][1]]:
		d[s[i][1]] -= 1
		d[s[i][0]] += 1
		ans.append(s[i][0])
	elif d[s[i][0]] > d[s[i][1]]:
		d[s[i][0]] -= 1
		d[s[i][1]] += 1
		ans.append(s[i][1])
	elif i < n - 1 and s[i + 1].strip(s[i]) != '' and (d[s[i + 1].strip(s[i])] == 0):
		string = s[i + 1].strip(s[i + 1].strip(s[i]))
		d[string] += 1
		d[s[i].strip(string)] -= 1
		ans.append(s[i + 1].strip(s[i + 1].strip(s[i])))
	else:
		d[s[i][0]] += 1
		d[s[i][1]] -= 1
		ans.append(s[i][0])
print('Yes')
for i in range(len(ans)):
	print(ans[i])


(n, *x) = map(int, input().split())
k = 'ABC'
ans = []
s = [input() for _ in range(n)]
for p in range(n):
	sp = s[p]
	if sp == 'AB':
		i = 0
		j = 1
	elif sp == 'BC':
		i = 1
		j = 2
	else:
		i = 0
		j = 2
	if x[i] == x[j] == 0:
		print('No')
		break
	if x[i] == x[j] and p < n - 1:
		sp1 = s[p + 1]
		if k[i] in sp1:
			x[i] += 1
			x[j] -= 1
			ans.append(k[i])
		else:
			x[i] -= 1
			x[j] += 1
			ans.append(k[j])
	elif x[i] < x[j]:
		x[i] += 1
		x[j] -= 1
		ans.append(k[i])
	else:
		x[i] -= 1
		x[j] += 1
		ans.append(k[j])
else:
	print('Yes')
	print(*ans, sep='\n')


(N, A, B, C) = list(map(int, input().split()))
S = [input() for _ in range(N)]

def main():
	l = [A, B, C]
	d = {'AB': (0, 1, 2), 'AC': (0, 2, 1), 'BC': (1, 2, 0)}
	dl = ['A', 'B', 'C']
	ans = []
	for n in range(N):
		(i, j, k) = d[S[n]]
		if l[i] < l[j]:
			l[i] += 1
			l[j] -= 1
			ans.append(dl[i])
		elif l[i] > l[j]:
			l[i] -= 1
			l[j] += 1
			ans.append(dl[j])
		elif l[i] == 0:
			print('No')
			return
		else:
			if n < N - 1 and j == d[S[n + 1]][2]:
				(i, j) = (j, i)
			l[i] -= 1
			l[j] += 1
			ans.append(dl[j])
	print('Yes')
	print('\n'.join(ans))
main()


(n, a, b, c) = map(int, input().split())
op = [input() for i in range(n)]
val = [a, b, c]
flag = True
ansls = list()
for i in range(n):
	s1 = ord(op[i][0]) - ord('A')
	s2 = ord(op[i][1]) - ord('A')
	if val[s1] > val[s2]:
		ansls.append(s2)
		val[s2] += 1
		val[s1] -= 1
	elif val[s1] < val[s2] or i + 1 == n:
		ansls.append(s1)
		val[s1] += 1
		val[s2] -= 1
	else:
		s1n = ord(op[i + 1][0]) - ord('A')
		s2n = ord(op[i + 1][1]) - ord('A')
		nxt = set([s1, s2]) & set([s1n, s2n])
		nxt = list(nxt)[0]
		ansls.append(nxt)
		val[nxt] += 1
		if nxt == s1:
			val[s2] -= 1
		else:
			val[s1] -= 1
	if min(val) < 0:
		flag = False
		break
if flag:
	print('Yes')
	for i in range(n):
		print(chr(ansls[i] + ord('A')))
else:
	print('No')


def main():
	(N, A, B, C) = list(map(int, input().split()))
	d = {'A': A, 'B': B, 'C': C}
	l = []
	for _ in range(N):
		s = input()
		l.append(s)
	r = []
	for i in range(N):
		(x, y) = (l[i][0], l[i][1])
		z = 'A'
		for j in d:
			if j not in l[i]:
				z = j
		if d[x] > d[y]:
			d[x] -= 1
			d[y] += 1
			r.append(y)
		elif d[y] > d[x]:
			d[x] += 1
			d[y] -= 1
			r.append(x)
		else:
			if d[x] > 1 or i == N - 1:
				d[x] += 1
				d[y] -= 1
				r.append(x)
			elif set(l[i]) == set(l[i + 1]):
				d[x] += 1
				d[y] -= 1
				r.append(x)
			else:
				x2 = 'A'
				for j in l[i + 1]:
					if j != z:
						if j == y:
							(x, y) = (y, x)
				if d[z] > 1:
					d[x] -= 1
					d[y] += 1
					r.append(y)
				else:
					d[x] += 1
					d[y] -= 1
					r.append(x)
			if d[x] < 0 or d[y] < 0 or d[z] < 0:
				return (False, r)
	return (True, r)
(x, y) = main()
if x:
	print('Yes')
	for i in y:
		print(i)
else:
	print('No')


(N, *v) = map(int, input().split())
S = [input() for _ in range(N)]
Z = []
for (i, s, t) in zip(range(N), S, S[1:] + ['ZZ']):
	(a, b, c) = v
	if s == 'AB':
		if a == b == 0:
			print('No')
			return
		elif a < b:
			v[0] += 1
			v[1] -= 1
			Z.append('A')
		elif a > b:
			v[0] -= 1
			v[1] += 1
			Z.append('B')
		elif t == 'AC':
			v[0] += 1
			v[1] -= 1
			Z.append('A')
		else:
			v[0] -= 1
			v[1] += 1
			Z.append('B')
	elif s == 'AC':
		if a == c == 0:
			print('No')
			return
		elif a < c:
			v[0] += 1
			v[2] -= 1
			Z.append('A')
		elif a > c:
			v[0] -= 1
			v[2] += 1
			Z.append('C')
		elif t == 'AB':
			v[0] += 1
			v[2] -= 1
			Z.append('A')
		else:
			v[0] -= 1
			v[2] += 1
			Z.append('C')
	elif b == c == 0:
		print('No')
		return
	elif b < c:
		v[1] += 1
		v[2] -= 1
		Z.append('B')
	elif b > c:
		v[1] -= 1
		v[2] += 1
		Z.append('C')
	elif t == 'AB':
		v[1] += 1
		v[2] -= 1
		Z.append('B')
	else:
		v[1] -= 1
		v[2] += 1
		Z.append('C')
print('Yes')
for z in Z:
	print(z)


(n, a, b, c) = map(int, input().split())
A = [a, b, c]
D = {'AB': 0, 'BC': 1, 'AC': 2}
S = [input() for i in range(n)]
S.append('AB')
X = []
for i in range(n):
	(x, y) = (D[S[i]], (D[S[i]] + 1) % 3)
	if A[x] == 0 and A[y] == 0:
		print('No')
		return
	if A[x] < A[y]:
		(A[x], A[y]) = (A[x] + 1, A[y] - 1)
		X.append('ABC'[x])
	elif A[x] > A[y]:
		(A[x], A[y]) = (A[x] - 1, A[y] + 1)
		X.append('ABC'[y])
	else:
		(x1, y1) = (D[S[i + 1]], (D[S[i + 1]] + 1) % 3)
		if x == y1:
			(A[x], A[y]) = (A[x] + 1, A[y] - 1)
			X.append('ABC'[x])
		else:
			(A[x], A[y]) = (A[x] - 1, A[y] + 1)
			X.append('ABC'[y])
print('Yes')
print(*X, sep='\n')


(n, *a) = [int(i) for i in input().split()]
abc = 'ABC'
xy = []
for _ in range(n):
	xy.append([abc.index(i) for i in input()])
i = 0
ans = []
while i < n:
	if a[xy[i][0]] == 1 and a[xy[i][1]] == 1:
		j = list(set([0, 1, 2]) - set(xy[i]))[0]
		if i == n - 1 or a[j] != 0 or xy[i] == xy[i + 1]:
			if a[xy[i][0]] > a[xy[i][1]]:
				ans.append(abc[xy[i][1]])
				a[xy[i][0]] -= 1
				a[xy[i][1]] += 1
			else:
				ans.append(abc[xy[i][0]])
				a[xy[i][1]] -= 1
				a[xy[i][0]] += 1
			i += 1
		else:
			k = list(set(xy[i + 1]) - set([j]))[0]
			ans.append(abc[k])
			a[k] += 1
			a[list(set(xy[i]) - set([k]))[0]] -= 1
			i += 1
	else:
		if a[xy[i][0]] > a[xy[i][1]]:
			ans.append(abc[xy[i][1]])
			a[xy[i][0]] -= 1
			a[xy[i][1]] += 1
		else:
			ans.append(abc[xy[i][0]])
			a[xy[i][1]] -= 1
			a[xy[i][0]] += 1
		i += 1
	if min(a) < 0:
		print('No')
		exit()
print('Yes')
for i in ans:
	print(i)


import sys

def input():
	return sys.stdin.readline().strip()

def solve():

	def distribute(fm, to):
		count[fm] -= 1
		count[to] += 1
		ans.append(to)
	(n, a, b, c) = map(int, input().split())
	queries = [input() for _ in range(n)]
	count = {'A': a, 'B': b, 'C': c}
	ans = ['Yes']
	for i in range(n):
		(x, y) = queries[i]
		if count[x] == count[y] == 0:
			return 'No'
		elif count[x] == count[y] == 1:
			if i == n - 1:
				distribute(x, y)
			elif x in queries[i + 1]:
				distribute(y, x)
			else:
				distribute(x, y)
		elif count[y] > count[x]:
			distribute(y, x)
		else:
			distribute(x, y)
	return '\n'.join(ans)
print(solve())


(N, A, B, C) = map(int, input().split())
ans = []
d = {'A': A, 'B': B, 'C': C}
s = [input() for _ in range(N)]

def add_ans(s1, s2):
	d[s1] += 1
	d[s2] -= 1
	ans.append(s1)
for i in range(N):
	now = s[i]
	x = now[0]
	y = now[1]
	if d[x] == d[y] == 0:
		print('No')
		exit()
	elif d[x] == 0:
		add_ans(x, y)
	elif d[y] == 0:
		add_ans(y, x)
	elif i == N - 1:
		add_ans(x, y)
	elif x in s[i + 1]:
		add_ans(x, y)
	else:
		add_ans(y, x)
print('Yes')
for i in ans:
	print(i)


import sys
input = sys.stdin.readline
(n, a, b, c) = [int(x) for x in input().split()]
score = {}
score['A'] = a
score['B'] = b
score['C'] = c
S = [input().rstrip() for _ in range(n)]
ans = []
for i in range(n - 1):
	s = S[i]
	next_s = S[i + 1]
	s1 = s[0]
	s2 = s[1]
	if score[s1] == 0 and score[s2] == 0:
		print('No')
		sys.exit()
	elif score[s1] == 0:
		ans.append(s1)
		score[s1] += 1
		score[s2] -= 1
	elif score[s2] == 0:
		ans.append(s2)
		score[s1] -= 1
		score[s2] += 1
	elif next_s == s:
		ans.append(s1)
		score[s1] += 1
		score[s2] -= 1
	elif s1 in next_s:
		ans.append(s1)
		score[s1] += 1
		score[s2] -= 1
	else:
		ans.append(s2)
		score[s2] += 1
		score[s1] -= 1
s = S[-1]
s1 = s[0]
s2 = s[1]
if score[s1] == 0 and score[s2] == 0:
	print('No')
	sys.exit()
elif score[s1] == 0:
	ans.append(s1)
	score[s1] += 1
	score[s2] -= 1
elif score[s2] == 0:
	ans.append(s2)
	score[s1] -= 1
	score[s2] += 1
else:
	ans.append(s1)
print('Yes')
for i in ans:
	print(i)


import sys
input = sys.stdin.readline
(n, a, b, c) = map(int, input().split())
S = [input().rstrip().replace('AC', 'CA') for _ in range(n)]
D = ['AB', 'BC', 'CA']
X = [a + b, b + c, c + a]
L = []
for (i, s) in enumerate(S):
	k = D.index(s)
	if X[k] == 0:
		print('No')
		return
	if X[(k + 1) % 3] == 1 and X[(k + 2) % 3] == 1 and (i < n - 1):
		l = D.index(S[i + 1])
		if l == (k + 1) % 3:
			X[(k + 1) % 3] += 1
			X[(k + 2) % 3] -= 1
			L.append(s[1])
		else:
			X[(k + 2) % 3] += 1
			X[(k + 1) % 3] -= 1
			L.append(s[0])
	elif X[(k + 1) % 3] < X[(k + 2) % 3]:
		X[(k + 1) % 3] += 1
		X[(k + 2) % 3] -= 1
		L.append(s[1])
	else:
		X[(k + 2) % 3] += 1
		X[(k + 1) % 3] -= 1
		L.append(s[0])
print('Yes')
print(*L, sep='\n')


(n, a, b, c) = map(int, input().split())
s = [input() for i in range(n)]
dic = {'A': a, 'B': b, 'C': c}
l = []
for i in range(n):
	temp1 = s[i][0]
	temp2 = s[i][1]
	if dic[temp1] == 0 and dic[temp2] == 0:
		print('No')
		exit()
	if dic[temp1] < dic[temp2]:
		dic[temp1] += 1
		dic[temp2] -= 1
		l.append(temp1)
	elif dic[temp1] == dic[temp2] and i != n - 1:
		(n1, n2) = s[i + 1]
		if (n1, n2) == (temp1, temp2):
			dic[temp2] += 1
			dic[temp1] -= 1
			l.append(temp2)
		elif temp1 == n1 or temp1 == n2:
			dic[temp1] += 1
			dic[temp2] -= 1
			l.append(temp1)
		else:
			dic[temp2] += 1
			dic[temp1] -= 1
			l.append(temp2)
	else:
		dic[temp2] += 1
		dic[temp1] -= 1
		l.append(temp2)
print('Yes')
print(*l, sep='\n')


(N, *X) = map(int, input().split())
S = [input() for i in range(N)]
f = 1
d = {'AB': (0, 1), 'AC': (0, 2), 'BC': (1, 2)}
x = 'ABC'
a = []
for i in range(N):
	if X[d[S[i]][0]] == 1 and X[d[S[i]][1]] == 1 and (X.count(0) == 1) and (i < N - 1):
		if S[i][0] in S[i + 1]:
			X[d[S[i]][0]] += 1
			X[d[S[i]][1]] -= 1
			a.append(x[d[S[i]][0]])
		else:
			X[d[S[i]][0]] -= 1
			X[d[S[i]][1]] += 1
			a.append(x[d[S[i]][1]])
	elif X[d[S[i]][0]] < X[d[S[i]][1]]:
		X[d[S[i]][0]] += 1
		X[d[S[i]][1]] -= 1
		a.append(x[d[S[i]][0]])
	else:
		X[d[S[i]][0]] -= 1
		X[d[S[i]][1]] += 1
		a.append(x[d[S[i]][1]])
	if -1 in X:
		f = 0
		break
print(['No', 'Yes'][f])
if f:
	print(*a, sep='\n')


def main():
	(N, A, B, C) = [int(i) for i in input().split()]
	if A == B == C == 0:
		print('No')
		return
	S = [input() for _ in range(N)]
	d = {'A': A, 'B': B, 'C': C}
	order = []
	for (i, s) in enumerate(S):
		(s1, s2) = s
		if d[s1] == d[s2] == 0:
			print('No')
			return
		elif d[s1] == 0:
			d[s1] += 1
			d[s2] -= 1
			order.append(s1)
		elif d[s2] == 0:
			d[s2] += 1
			d[s1] -= 1
			order.append(s2)
		elif d[s1] == d[s2] == 1:
			try:
				if s1 in S[i + 1]:
					d[s1] += 1
					d[s2] -= 1
					order.append(s1)
				else:
					d[s2] += 1
					d[s1] -= 1
					order.append(s2)
			except:
				order.append(s1)
		elif d[s1] > d[s2]:
			d[s1] -= 1
			d[s2] += 1
			order.append(s2)
		else:
			d[s2] -= 1
			d[s1] += 1
			order.append(s1)
	print('Yes')
	for o in order:
		print(o)
main()


(n, a, b, c) = map(int, input().split())
d = {'A': a, 'B': b, 'C': c}
res = []
s_l = [input() for _ in range(n)]
for (i, s) in enumerate(s_l):
	s0 = s[0]
	s1 = s[1]
	if d[s0] == d[s1] == 0:
		print('No')
		exit()
	elif d[s0] == 0:
		d[s0] += 1
		d[s1] -= 1
		res.append(s0)
	elif d[s1] == 0:
		d[s0] -= 1
		d[s1] += 1
		res.append(s1)
	elif i == n - 1:
		res.append(s0)
	elif s0 in s_l[i + 1]:
		d[s0] += 1
		d[s1] -= 1
		res.append(s0)
	else:
		d[s0] -= 1
		d[s1] += 1
		res.append(s1)
print('Yes')
for r in res:
	print(r)


(n, A, B, C) = map(int, input().split())
r = [A, B, C]
g = list()
for i in range(n):
	g.append(str(input()))

def re(string):
	if string == 'AB':
		return (0, 1)
	elif string == 'AC':
		return (0, 2)
	else:
		return (1, 2)

def al(num):
	if num == 0:
		return 'A'
	elif num == 1:
		return 'B'
	else:
		return 'C'
flag = 0
result = list()
for i in range(n):
	(a, b) = re(g[i])
	if r[a] == 0 and r[b] == 0:
		print('No')
		flag = 1
		break
	elif r[a] > r[b]:
		r[a] -= 1
		r[b] += 1
		result.append(al(b))
	elif r[a] < r[b]:
		r[a] += 1
		r[b] -= 1
		result.append(al(a))
	else:
		if i + 1 == n:
			r[a] += 1
			r[b] -= 1
			result.append(al(a))
			break
		(x, y) = re(g[i + 1])
		if (x, y) == (a, b):
			r[a] += 1
			r[b] -= 1
			result.append(al(a))
		elif x in (a, b):
			r[x] += 2
			r[a] -= 1
			r[b] -= 1
			result.append(al(x))
		else:
			r[y] += 2
			r[a] -= 1
			r[b] -= 1
			result.append(al(y))
if flag == 0:
	print('Yes')
	for item in result:
		print(item)


def add_i1():
	abc[i1] += 1
	abc[i2] -= 1
	res[i] = i1
	return

def add_i2():
	abc[i1] -= 1
	abc[i2] += 1
	res[i] = i2
(n, *abc) = map(int, input().split())
ip = [0] * n
for i in range(n):
	ip[i] = list(map(lambda x: ord(x) - ord('A'), list(input())))
ans = 'Yes'
res = [0] * n
s = sum(abc)
if s == 0:
	ans = 'No'
elif s == 1:
	for i in range(n):
		i1 = ip[i][0]
		i2 = ip[i][1]
		ABC = [abc[i1], abc[i2]]
		if ABC == [0, 0]:
			ans = 'No'
		elif ABC == [0, 1]:
			add_i1()
		else:
			add_i2()
else:
	i1 = ip[0][0]
	i2 = ip[0][1]
	if [abc[i1], abc[i2]] == [0, 0]:
		ans = 'No'
	else:
		for i in range(n):
			i1 = ip[i][0]
			i2 = ip[i][1]
			if abc[i1] == 0:
				add_i1()
			elif abc[i2] == 0:
				add_i2()
			elif i + 1 < n and ip[i + 1] != ip[i]:
				c = list(set(ip[i]) & set(ip[i + 1]))[0]
				if i1 == c:
					add_i1()
				else:
					add_i2()
			else:
				add_i1()
dic = {0: 'A', 1: 'B', 2: 'C'}
print(ans)
if ans == 'Yes':
	for i in range(n):
		print(dic[res[i]])


(N, A, B, C) = list(map(int, input().split()))
s = [input() for _ in range(N)]
DP = [[0] * 3 for _ in range(N + 1)]
DP[0] = [A, B, C]
L = [''] * N
R = {}
R[0] = 'A'
R[1] = 'B'
R[2] = 'C'
A = []
B = []
for i in range(N):
	t = s[i]
	if t == 'AB':
		x = 0
		y = 1
	if t == 'BC':
		x = 1
		y = 2
	if t == 'AC':
		x = 0
		y = 2
	if DP[i][y] != 0:
		DP[i + 1] = DP[i]
		DP[i + 1][x] += 1
		DP[i + 1][y] -= 1
		L[i] = R[x]
		if x == 0:
			A.append([i, y])
		else:
			B.append([i, y])
	elif DP[i][x] != 0:
		DP[i + 1] = DP[i]
		DP[i + 1][x] -= 1
		DP[i + 1][y] += 1
		L[i] = R[y]
	else:
		if x == 0:
			if len(B) == 0:
				print('No')
				exit()
			z = 1
			(k, n) = B.pop()
		if x == 1:
			if len(A) == 0:
				print('No')
				exit()
			z = 0
			(k, n) = A.pop()
		DP[i + 1] = DP[i]
		DP[i + 1][z] -= 2
		DP[i + 1][n] += 2
		if n == x:
			(x, y) = (y, x)
		DP[i + 1][x] += 1
		DP[i + 1][y] -= 1
		if DP[i + 1][z] < 0:
			print('No')
			exit()
		L[i] = R[x]
		L[k] = R[y]
print('Yes')
for i in L:
	print(i)


(n, a, b, c) = list(map(int, input().split()))
ss = []
for i in range(n):
	ss.append(input())
ans = []
num_dic = {'A': a, 'B': b, 'C': c}
for i in range(n):
	s = ss[i]
	if num_dic[s[0]] == 0 and num_dic[s[1]] == 0:
		print('No')
		exit()
	elif num_dic[s[0]] > num_dic[s[1]]:
		num_dic[s[0]] -= 1
		num_dic[s[1]] += 1
		ans.append(s[1])
	elif num_dic[s[0]] < num_dic[s[1]]:
		num_dic[s[0]] += 1
		num_dic[s[1]] -= 1
		ans.append(s[0])
	elif i == n - 1:
		ans.append(s[0])
		num_dic[s[0]] -= 1
		num_dic[s[1]] += 1
	elif s[0] in ss[i + 1]:
		num_dic[s[0]] += 1
		num_dic[s[1]] -= 1
		ans.append(s[0])
	else:
		num_dic[s[0]] -= 1
		num_dic[s[1]] += 1
		ans.append(s[1])
print('Yes')
for a in ans:
	print(a)


(n, a, b, c) = map(int, input().split())
s = [input() for i in range(n)]
ans = []
from collections import defaultdict
d = defaultdict(int)
d['A'] = a
d['B'] = b
d['C'] = c

def add(c1, c2):
	global d
	ans.append(c1)
	d[c1] += 1
	d[c2] -= 1
for i in range(n):
	que = s[i]
	nxt = 'NONE'
	if i != n - 1:
		nxt = s[i + 1]
	(q1, q2) = que
	if d[q1] == d[q2] == 0:
		print('No')
		exit()
	if d[q1] == d[q2] == 1:
		if q1 in nxt:
			add(q1, q2)
		else:
			add(q2, q1)
	elif d[q1] >= d[q2]:
		add(q2, q1)
	else:
		add(q1, q2)
print('Yes')
for a in ans:
	print(a)


(N, A, B, C) = map(int, input().split())
ss = [input() for _ in range(N)]
history = []

def move_to_flatten(s):
	nonlocal A, B, C, history
	if s == 'AB':
		if A >= B:
			A -= 1
			B += 1
			history.append('B')
		else:
			B -= 1
			A += 1
			history.append('A')
	elif s == 'BC':
		if B >= C:
			B -= 1
			C += 1
			history.append('C')
		else:
			C -= 1
			B += 1
			history.append('B')
	elif s == 'AC':
		if A >= C:
			A -= 1
			C += 1
			history.append('C')
		else:
			C -= 1
			A += 1
			history.append('A')
for (i, s) in enumerate(ss):
	zeros = (A, B, C).count(0)
	if zeros == 0:
		move_to_flatten(s)
	elif zeros == 1:
		if A + B + C == 2:
			if A == 0:
				if s == 'BC':
					if i + 1 < N and 'B' in ss[i + 1]:
						C -= 1
						B += 1
						history.append('B')
					else:
						B -= 1
						C += 1
						history.append('C')
				else:
					move_to_flatten(s)
			elif B == 0:
				if s == 'AC':
					if i + 1 < N and 'C' in ss[i + 1]:
						A -= 1
						C += 1
						history.append('C')
					else:
						C -= 1
						A += 1
						history.append('A')
				else:
					move_to_flatten(s)
			elif C == 0:
				if s == 'AB':
					if i + 1 < N and 'A' in ss[i + 1]:
						B -= 1
						A += 1
						history.append('A')
					else:
						A -= 1
						B += 1
						history.append('B')
				else:
					move_to_flatten(s)
		else:
			move_to_flatten(s)
	elif zeros == 2:
		if A != 0 and s == 'BC':
			print('No')
			return
		elif B != 0 and s == 'AC':
			print('No')
			return
		elif C != 0 and s == 'AB':
			print('No')
			return
		move_to_flatten(s)
	else:
		print('No')
		return
print('Yes')
print(*history, sep='\n')


(n, a, b, c) = (int(x) for x in input().split())
d = {'A': a, 'B': b, 'C': c}
S = [input() for _ in range(n)]
ANS = []
for (i, s) in enumerate(S):
	if d[s[0]] == 0 and d[s[1]] == 0:
		print('No')
		exit()
	elif d[s[0]] > d[s[1]] or (d[s[0]] == d[s[1]] == 1 and i < n - 1 and (s[1] in S[i + 1])):
		d[s[1]] += 1
		d[s[0]] -= 1
		ANS.append(s[1])
	else:
		d[s[0]] += 1
		d[s[1]] -= 1
		ANS.append(s[0])
print('Yes')
for ans in ANS:
	print(ans)


(n, a, b, c) = list(map(int, input().split()))
l = []
for i in range(0, n):
	s = input()
	l.append(s)
final = []
for i in range(0, len(l)):
	if l[i] == 'AB':
		if a > b:
			b += 1
			a -= 1
			final.append('B')
		elif a < b:
			b -= 1
			a += 1
			final.append('A')
		elif a == 0:
			print('No')
			break
		elif i != len(l) - 1:
			if l[i + 1] == 'AB':
				a += 1
				b -= 1
				final.append('A')
			elif l[i + 1] == 'AC':
				a += 1
				b -= 1
				final.append('A')
			else:
				a -= 1
				b += 1
				final.append('B')
		else:
			a -= 1
			b += 1
			final.append('B')
	elif l[i] == 'AC':
		if a > c:
			c += 1
			a -= 1
			final.append('C')
		elif a < c:
			c -= 1
			a += 1
			final.append('A')
		elif a == 0:
			print('No')
			break
		elif i != len(l) - 1:
			if l[i + 1] == 'AB':
				a += 1
				c -= 1
				final.append('A')
			elif l[i + 1] == 'AC':
				a += 1
				c -= 1
				final.append('A')
			else:
				a -= 1
				c += 1
				final.append('C')
		else:
			a -= 1
			c += 1
			final.append('C')
	elif b > c:
		c += 1
		b -= 1
		final.append('C')
	elif b < c:
		c -= 1
		b += 1
		final.append('B')
	elif b == 0:
		print('No')
		break
	elif i != len(l) - 1:
		if l[i + 1] == 'AB':
			b += 1
			c -= 1
			final.append('B')
		elif l[i + 1] == 'BC':
			b += 1
			c -= 1
			final.append('B')
		else:
			b -= 1
			c += 1
			final.append('C')
	else:
		b -= 1
		c += 1
		final.append('C')
else:
	print('Yes')
	for i in range(0, len(final)):
		print(final[i])


import sys
sys.setrecursionlimit(10 ** 6)
(Q, A, B, C) = map(int, input().split())

def conv(s):
	return (0, 1) if s == 'AB' else (1, 2) if s == 'BC' else (0, 2)
S = [conv(input()) for i in range(Q)]
N = [A, B, C]
ans = []

def dfs(i):
	global ans, N
	if N[0] < 0 or N[1] < 0 or N[2] < 0:
		return
	if i == Q:
		print('Yes')
		for idx in ans:
			print('ABC'[idx])
		exit()
	(x, y) = S[i]
	for _ in range(2):
		N[x] += 1
		N[y] -= 1
		ans.append(x)
		dfs(i + 1)
		N[x] -= 1
		N[y] += 1
		ans.pop()
		(x, y) = (y, x)
dfs(0)
print('No')


(n, a, b, c) = map(int, input().split())
abc = [a, b, c]

def yes():
	print('Yes')
	for c in ans:
		print(chr(c + ord('A')))

def no():
	print('No')
	exit()

def move(s, t):
	ans.append(s)
	abc[s] += 1
	abc[t] -= 1
play = []
for i in range(n):
	s = bytes(input(), 'ascii')
	(s, t) = (s[0] - ord('A'), s[1] - ord('A'))
	play.append((s, t))
ans = []
for (i, (s, t)) in enumerate(play):
	if abc[s] == 0 and abc[t] == 0:
		no()
		break
	if abc[s] == abc[t]:
		if s in play[(i + 1) % n]:
			move(s, t)
		else:
			move(t, s)
	elif abc[s] < abc[t]:
		move(s, t)
	else:
		move(t, s)
yes()


def f_three_variables_game():
	(N, A, B, C) = list(map(int, input().split()))
	Selections = [input() for i in range(N)]
	count = {'A': A, 'B': B, 'C': C}
	ans = []
	for (turn, string) in enumerate(Selections):
		(s0, s1) = string
		(variable_up, variable_down) = (None, None)
		if count[s0] == count[s1] == 0:
			return 'No'
		elif count[s0] == 0:
			(variable_up, variable_down) = (s0, s1)
		elif count[s1] == 0:
			(variable_up, variable_down) = (s1, s0)
		elif turn + 1 == N:
			(variable_up, variable_down) = (s0, s1)
		elif s0 in Selections[turn + 1]:
			(variable_up, variable_down) = (s0, s1)
		else:
			(variable_up, variable_down) = (s1, s0)
		count[variable_up] += 1
		count[variable_down] -= 1
		ans.append(variable_up)
	return ' '.join(['Yes'] + ans)
print(f_three_variables_game())


import collections

def main():
	(N, A, B, C) = map(int, input().split())
	ans = ''
	s = []
	for _ in range(N):
		s.append(input())
	d = dict()
	d['A'] = A
	d['B'] = B
	d['C'] = C
	ans = ''
	for i in range(N):
		if d[s[i][0]] == 0 and d[s[i][1]] == 0:
			break
		elif d[s[i][0]] == 0:
			d[s[i][0]] += 1
			d[s[i][1]] -= 1
			ans += s[i][0]
		elif d[s[i][1]] == 0:
			d[s[i][1]] += 1
			d[s[i][0]] -= 1
			ans += s[i][1]
		elif d[s[i][0]] == 1 and d[s[i][1]] == 1 and (d['A'] + d['B'] + d['C'] == 2):
			if i < N - 1 and s[i] != s[i + 1] and (s[i][0] in s[i + 1]):
				d[s[i][0]] += 1
				d[s[i][1]] -= 1
				ans += s[i][0]
			else:
				d[s[i][1]] += 1
				d[s[i][0]] -= 1
				ans += s[i][1]
		elif d[s[i][0]] < d[s[i][1]]:
			d[s[i][0]] += 1
			d[s[i][1]] -= 1
			ans += s[i][0]
		else:
			d[s[i][1]] += 1
			d[s[i][0]] -= 1
			ans += s[i][1]
	if len(ans) == N:
		print('Yes')
		for c in ans:
			print(c)
	else:
		print('No')
main()


(N, A, B, C) = map(int, input().split())
S = [''] * (N + 1)
for a in range(N):
	S[a] = input()
ans = 'Yes'
L_ans = [''] * (N + 1)
i = 0
while i < N:
	if S[i] == 'AB':
		if A > B:
			B += 1
			A -= 1
			L_ans[i] = 'B'
		elif A < B:
			A += 1
			B -= 1
			L_ans[i] = 'A'
		elif A == B and S[i + 1] == 'BC':
			B += 1
			A -= 1
			L_ans[i] = 'B'
		else:
			A += 1
			B -= 1
			L_ans[i] = 'A'
	elif S[i] == 'AC':
		if A > C:
			C += 1
			A -= 1
			L_ans[i] = 'C'
		elif A < C:
			A += 1
			C -= 1
			L_ans[i] = 'A'
		elif A == C and S[i + 1] == 'BC':
			C += 1
			A -= 1
			L_ans[i] = 'C'
		else:
			A += 1
			C -= 1
			L_ans[i] = 'A'
	elif S[i] == 'BC':
		if C > B:
			B += 1
			C -= 1
			L_ans[i] = 'B'
		elif C < B:
			C += 1
			B -= 1
			L_ans[i] = 'C'
		elif B == C and S[i + 1] == 'AB':
			B += 1
			C -= 1
			L_ans[i] = 'B'
		else:
			C += 1
			B -= 1
			L_ans[i] = 'C'
	i += 1
	if any([A < 0, B < 0, C < 0]):
		ans = 'No'
		break
print(ans)
if ans == 'Yes':
	j = 0
	while j < N:
		print(L_ans[j])
		j += 1


import sys
sys.setrecursionlimit(1 << 30)
idx = 'ABC'
(N, *vals) = map(int, input().split())
evs = [tuple(map(idx.index, input())) for _ in range(N)]

def f(i, vals, path):
	if i == len(evs):
		print('Yes')
		print('\n'.join(path))
		raise SystemExit
	(k, j) = evs[i]
	for (add, sub) in ((k, j), (j, k)):
		if vals[sub] == 0:
			continue
		vals[add] += 1
		vals[sub] -= 1
		path.append(idx[add])
		f(i + 1, vals, path)
		vals[add] -= 1
		vals[sub] += 1
		path.pop()
f(0, vals, [])
print('No')


import sys
sysread = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def run():
	pri = []
	(N, A, B, C) = map(int, sysread().split())
	vals = {'A': A, 'B': B, 'C': C}
	S = [sysread() for _ in range(N)]
	pri = []
	for (idx, s) in enumerate(S):
		if vals[s[0]] == vals[s[1]] and vals[s[0]] == 1 and (idx != len(S) - 1):
			if s[0] in S[idx + 1]:
				vals[s[0]] += 1
				vals[s[1]] -= 1
				pri.append(s[0])
			else:
				vals[s[0]] -= 1
				vals[s[1]] += 1
				pri.append(s[1])
		elif vals[s[0]] <= vals[s[1]]:
			vals[s[0]] += 1
			vals[s[1]] -= 1
			pri.append(s[0])
		else:
			vals[s[0]] -= 1
			vals[s[1]] += 1
			pri.append(s[1])
		if not check_vals(vals):
			print('No')
			return None
	print('Yes')
	for st in pri:
		print(st)

def check_vals(vals):
	for v in vals.values():
		if v < 0:
			return False
	return True
run()


(N, A, B, C) = map(int, input().split())
path = []
inputs = [input() for _ in range(N)]
for i in range(N):
	target = inputs[i]
	if target == 'AB':
		if A > B:
			A -= 1
			B += 1
			path.append('B')
		elif A == 1 and B == 1:
			if i != N - 1 and inputs[i + 1] == 'AC':
				A += 1
				B -= 1
				path.append('A')
			else:
				A -= 1
				B += 1
				path.append('B')
		else:
			A += 1
			B -= 1
			path.append('A')
	if target == 'AC':
		if A > C:
			A -= 1
			C += 1
			path.append('C')
		elif A == 1 and C == 1:
			if i != N - 1 and inputs[i + 1] == 'AB':
				A += 1
				C -= 1
				path.append('A')
			else:
				A -= 1
				C += 1
				path.append('C')
		else:
			A += 1
			C -= 1
			path.append('A')
	if target == 'BC':
		if B > C:
			B -= 1
			C += 1
			path.append('C')
		elif B == 1 and C == 1:
			if i != N - 1 and inputs[i + 1] == 'AB':
				B += 1
				C -= 1
				path.append('B')
			else:
				B -= 1
				C += 1
				path.append('C')
		else:
			B += 1
			C -= 1
			path.append('B')
	if A < 0 or B < 0 or C < 0:
		print('No')
		exit(0)
print('Yes')
for i in path:
	print(i)


(n, a, b, c) = map(int, input().split())
s = [0] * (n + 1)
for i in range(n):
	s[i] = input()
l = [0] * (n + 1)
for i in range(n):
	if s[i] == 'AB':
		if a == b == 0:
			print('No')
			return
		if a + b + c == 2:
			if a == b == 1:
				if s[i + 1] == 'AC':
					a += 1
					b -= 1
					l[i] = 'A'
					continue
				elif s[i + 1] == 'BC':
					a -= 1
					b += 1
					l[i] = 'B'
					continue
		if a >= b:
			a -= 1
			b += 1
			l[i] = 'B'
		else:
			a += 1
			b -= 1
			l[i] = 'A'
	if s[i] == 'BC':
		if c == b == 0:
			print('No')
			return
		if a + b + c == 2:
			if b == c == 1:
				if s[i + 1] == 'AB':
					c -= 1
					b += 1
					l[i] = 'B'
					continue
				elif s[i + 1] == 'AC':
					b -= 1
					c += 1
					l[i] = 'C'
					continue
		if b >= c:
			b -= 1
			c += 1
			l[i] = 'C'
		else:
			b += 1
			c -= 1
			l[i] = 'B'
	if s[i] == 'AC':
		if a == c == 0:
			print('No')
			return
		if a + b + c == 2:
			if a == c == 1:
				if s[i + 1] == 'AB':
					c -= 1
					a += 1
					l[i] = 'A'
					continue
				elif s[i + 1] == 'BC':
					a -= 1
					c += 1
					l[i] = 'C'
					continue
		if a >= c:
			a -= 1
			c += 1
			l[i] = 'C'
		else:
			a += 1
			c -= 1
			l[i] = 'A'
if l[-2] != 0:
	print('Yes')
	for i in range(n):
		print(l[i])


(N, A, B, C) = map(int, input().split(' '))
S = [input() for i in range(N)]
ans = []
if A + B + C == 0:
	print('No')
else:
	d = {'A': A, 'B': B, 'C': C}
	for (n, i) in enumerate(S):
		(l, r) = list(i)
		(L, R) = (d[l], d[r])
		if L == R == 0:
			print('No')
			exit()
		elif L == 0:
			ans.append(l)
			d[l] += 1
			d[r] -= 1
		elif R == 0:
			d[l] -= 1
			d[r] += 1
			ans.append(r)
		elif L == R == 1 and n != N - 1 and (i != S[n + 1]):
			if l in S[n + 1]:
				d[l] += 1
				d[r] -= 1
				ans.append(l)
			else:
				d[l] -= 1
				d[r] += 1
				ans.append(r)
		elif L >= R:
			d[l] -= 1
			d[r] += 1
			ans.append(r)
		else:
			d[l] += 1
			d[r] -= 1
			ans.append(l)
	print('Yes')
	for i in ans:
		print(i)


import sys
input = lambda : sys.stdin.readline().strip()
(N, A, B, C) = [int(x) for x in input().split()]
s = [input() for _ in range(N)]
abc = {'A': A, 'B': B, 'C': C}
can = True
moves = []
for i in range(N):
	moves.append(next((j for j in (0, 1) if abc[s[i][j]] < abc[s[i][j ^ 1]] or (abc[s[i][j]] == abc[s[i][j ^ 1]] and (i + 1 == N or s[i + 1] == s[i] or s[i][j ^ 1] not in s[i + 1])))))
	abc[s[i][moves[-1]]] += 1
	abc[s[i][moves[-1] ^ 1]] -= 1
	can &= all((x >= 0 for x in abc.values()))
if can:
	print('Yes')
	print(*(s[i][moves[i]] for i in range(N)), sep='\n')
else:
	print('No')


(n, a, b, c) = map(int, input().split())
l = [[*input()] for _ in range(n)]
l2 = l[1:] + ['ABC']
d = {'A': a, 'B': b, 'C': c}
a2 = a + 1
b2 = b + 1
c2 = c + 1
isNo = 0
if (a > 0) + (b > 0) + (c > 0) >= 1:
	if d[l[0][0]] == 0 and d[l[0][1]] == 0:
		isNo = 1
	elif a + b + c == 1:
		for (s, s2) in zip(l, l2):
			if d[s[0]] < d[s[1]]:
				d[s[1]] += -1
				d[s[0]] += 1
				if s[0] not in s2:
					isNo = 1
					break
			else:
				d[s[1]] += 1
				d[s[0]] += -1
				if s[1] not in s2:
					isNo = 1
					break
	else:
		isNo = 0
else:
	isNo = 1
d = {'A': a, 'B': b, 'C': c}
if isNo:
	print('No')
else:
	print('Yes')
	for (s, s2) in zip(l, l2):
		if d[s[0]] > d[s[1]]:
			d[s[0]] += -1
			d[s[1]] += 1
			print(s[1])
		elif d[s[0]] < d[s[1]]:
			d[s[1]] += -1
			d[s[0]] += 1
			print(s[0])
		elif s[0] in s2:
			d[s[1]] += -1
			d[s[0]] += 1
			print(s[0])
		else:
			d[s[0]] += -1
			d[s[1]] += 1
			print(s[1])


(n, a, b, c) = map(int, input().split())
s_list = []
for i in range(n):
	s = input()
	s_list.append(s)
if a + b + c == 0:
	print('No')
	return
move = []
if a + b + c == 1:
	for i in range(n):
		if s_list[i] == 'AB':
			if a == 0:
				a += 1
				b -= 1
				move.append('A')
			else:
				b += 1
				a -= 1
				move.append('B')
		if s_list[i] == 'BC':
			if b == 0:
				b += 1
				c -= 1
				move.append('B')
			else:
				c += 1
				b -= 1
				move.append('C')
		if s_list[i] == 'AC':
			if a == 0:
				a += 1
				c -= 1
				move.append('A')
			else:
				c += 1
				a -= 1
				move.append('C')
		if min(a, b, c) < 0:
			print('No')
			return
	print('Yes')
	for i in move:
		print(i)
else:
	for i in range(n):
		if i < n - 1:
			s_next = s_list[i + 1]
		if s_list[i] == 'AB':
			if a == 1 and b == 1 and (s_next != 'AB'):
				if s_next == 'BC':
					b += 1
					a -= 1
					move.append('B')
				else:
					a += 1
					b -= 1
					move.append('A')
			elif a < b:
				a += 1
				b -= 1
				move.append('A')
			else:
				b += 1
				a -= 1
				move.append('B')
		if s_list[i] == 'BC':
			if b == 1 and c == 1 and (s_next != 'BC'):
				if s_next == 'AB':
					b += 1
					c -= 1
					move.append('B')
				else:
					c += 1
					b -= 1
					move.append('C')
			elif b < c:
				b += 1
				c -= 1
				move.append('B')
			else:
				c += 1
				b -= 1
				move.append('C')
		if s_list[i] == 'AC':
			if a == 1 and c == 1 and (s_next != 'AC'):
				if s_next == 'AB':
					a += 1
					c -= 1
					move.append('A')
				else:
					c += 1
					a -= 1
					move.append('C')
			elif a < c:
				a += 1
				c -= 1
				move.append('A')
			else:
				c += 1
				a -= 1
				move.append('C')
		if min(a, b, c) < 0:
			print('No')
			return
	print('Yes')
	for i in move:
		print(i)


def solve():
	ans = []
	for (i, (x, y)) in enumerate(s):
		if num[x] > num[y]:
			(x, y) = (y, x)
		if num[x] == num[y] and i < n - 1:
			if y == s[i + 1][0] or y == s[i + 1][1]:
				(x, y) = (y, x)
		num[x] += 1
		num[y] -= 1
		ans.append(x)
		if num[y] < 0:
			return False
	return ans
from collections import defaultdict
import sys
(n, a, b, c) = map(int, input().split())
num = defaultdict(int)
s = [input() for _ in range(n)]
num['A'] = a
num['B'] = b
num['C'] = c
id = ['A', 'B', 'C']
ans = solve()
if ans:
	print('Yes')
	print(*ans, sep='\n')
else:
	print('No')


from sys import setrecursionlimit
setrecursionlimit(10 ** 6)
stdin = open(0)
(N, A, B, C) = map(int, stdin.readline().split())
S = stdin.read().split()
ans = [''] * N

def dfs(i, a, b, c):
	if a < 0 or b < 0 or c < 0:
		return
	if i == N:
		print('Yes')
		print('\n'.join(ans))
		quit()
	if S[i] == 'AB':
		ans[i] = 'A'
		dfs(i + 1, a + 1, b - 1, c)
		ans[i] = 'B'
		dfs(i + 1, a - 1, b + 1, c)
	elif S[i] == 'BC':
		ans[i] = 'B'
		dfs(i + 1, a, b + 1, c - 1)
		ans[i] = 'C'
		dfs(i + 1, a, b - 1, c + 1)
	else:
		ans[i] = 'A'
		dfs(i + 1, a + 1, b, c - 1)
		ans[i] = 'C'
		dfs(i + 1, a - 1, b, c + 1)
dfs(0, A, B, C)
print('No')


(n, a, b, c) = map(int, input().split())
s = [input() for _ in range(n)]
abc = [a, b, c]
d = {'A': 0, 'B': 1, 'C': 2}
dr = {0: 'A', 1: 'B', 2: 'C'}
ans = []
for (i, x) in enumerate(s):
	x = [d[y] for y in list(x)]
	if abc[x[0]] == abc[x[1]] == 1 and i < n - 1:
		nx = [d[y] for y in list(s[i + 1])]
		for (j, y) in enumerate(x):
			if y in nx:
				abc[y] += 1
				abc[x[(j + 1) % 2]] -= 1
				ans.append(dr[y])
				break
	elif abc[x[0]] > abc[x[1]]:
		abc[x[1]] += 1
		abc[x[0]] -= 1
		ans.append(dr[x[1]])
	else:
		abc[x[0]] += 1
		abc[x[1]] -= 1
		ans.append(dr[x[0]])
	for y in abc:
		if y < 0:
			print('No')
			exit()
print('Yes')
print(*ans, sep='\n')


(N, A, B, C) = map(int, input().split())
(SS, res) = ([], [])
for _ in range(N):
	SS.append(input().rstrip())
SS += ['#']
for i in range(N):
	S = SS[i]
	if S == 'AB':
		if A == B == 1:
			if SS[i + 1] == 'BC':
				(A, B) = (A - 1, B + 1)
				res.append('B')
			else:
				(A, B) = (A + 1, B - 1)
				res.append('A')
		elif A > B:
			(A, B) = (A - 1, B + 1)
			res.append('B')
		else:
			(A, B) = (A + 1, B - 1)
			res.append('A')
	if S == 'AC':
		if A == C == 1:
			if SS[i + 1] == 'BC':
				(A, C) = (A - 1, C + 1)
				res.append('C')
			else:
				(A, C) = (A + 1, C - 1)
				res.append('A')
		elif A > C:
			(A, C) = (A - 1, C + 1)
			res.append('C')
		else:
			(A, C) = (A + 1, C - 1)
			res.append('A')
	if S == 'BC':
		if B == C == 1:
			if SS[i + 1] == 'AC':
				(B, C) = (B - 1, C + 1)
				res.append('C')
			else:
				(B, C) = (B + 1, C - 1)
				res.append('B')
		elif B > C:
			(B, C) = (B - 1, C + 1)
			res.append('C')
		else:
			(B, C) = (B + 1, C - 1)
			res.append('B')
	if A < 0 or B < 0 or C < 0:
		print('No')
		exit()
print('Yes')
print(*res, sep='\n')


from sys import stdin, setrecursionlimit
setrecursionlimit(10 ** 9)

def input():
	return stdin.readline().strip()
(N, A, B, C) = map(int, input().split())
strings = [input() for _ in range(N)]

def dfs(index, hp):
	if index == N:
		return ''
	(s1, s2) = strings[index]
	if hp[s1] > 0:
		hp2 = hp.copy()
		hp2[s1] -= 1
		hp2[s2] += 1
		ret = dfs(index + 1, hp2)
		if ret != False:
			return s2 + ret
	if hp[s2] > 0:
		hp2 = hp.copy()
		hp2[s2] -= 1
		hp2[s1] += 1
		ret = dfs(index + 1, hp2)
		if ret != False:
			return s1 + ret
	return False
d = {'A': A, 'B': B, 'C': C}
ans = dfs(0, d)
if ans == False:
	print('No')
else:
	print('Yes')
	for c in ans:
		print(c)


(n, a, b, c) = list(map(int, input().split()))
s = [[0] * 2 for _ in range(n)]
S = []
for i in range(n):
	X = input()
	S += X
	cnt = 0
	for x in X:
		if x == 'A':
			s[i][cnt] = 0
		elif x == 'B':
			s[i][cnt] = 1
		else:
			s[i][cnt] = 2
		cnt += 1
if a + b + c == 0:
	exit(print('No'))
abc = [a, b, c]
ABC = ['A', 'B', 'C']
ans = [0] * n

def zero(xy):
	x = xy[0]
	y = xy[1]
	if abc[x] == 0 and abc[y] == 0:
		return (-1, -1)
	elif abc[x] == 0:
		return (x, y)
	elif abc[y] == 0:
		return (y, x)
	else:
		return (3, 3)

def main():
	global ans
	global abc
	for i in range(n):
		(x, y) = zero(s[i])
		if x == -1:
			exit(print('No'))
		if x == 3:
			if i < n - 1:
				if s[i][1] in s[i + 1]:
					x = s[i][1]
					y = s[i][0]
				else:
					x = s[i][0]
					y = s[i][1]
			else:
				x = s[i][0]
				y = s[i][1]
		ans[i] = x
		abc[x] += 1
		abc[y] -= 1
main()
print('Yes')
for i in range(n):
	print(ABC[ans[i]])


(N, A, B, C) = list(map(int, input().split()))
S = [''] * N
for i in range(N):
	S[i] = input()
result = []
kekka = True
for i in range(N):
	if A == 0 and B == 0 and (S[i] == 'AB') or (C == 0 and B == 0 and (S[i] == 'BC')) or (A == 0 and C == 0 and (S[i] == 'AC')):
		kekka = False
		break
	elif S[i] == 'AB':
		if A == 0:
			A += 1
			B -= 1
			result.append('A')
		elif B == 0:
			A -= 1
			B += 1
			result.append('B')
		elif A == 1 and B == 1 and (C == 0) and (i != N - 1):
			if S[i + 1] == 'AC':
				A += 1
				B -= 1
				result.append('A')
			else:
				A -= 1
				B += 1
				result.append('B')
		elif A > B:
			A -= 1
			B += 1
			result.append('B')
		else:
			A += 1
			B -= 1
			result.append('A')
	elif S[i] == 'AC':
		if A == 0:
			A += 1
			C -= 1
			result.append('A')
		elif C == 0:
			A -= 1
			C += 1
			result.append('C')
		elif A == 1 and C == 1 and (B == 0) and (i != N - 1):
			if S[i + 1] == 'AB':
				A += 1
				C -= 1
				result.append('A')
			else:
				A -= 1
				C += 1
				result.append('C')
		elif A > C:
			A -= 1
			C += 1
			result.append('C')
		else:
			A += 1
			C -= 1
			result.append('A')
	elif B == 0:
		B += 1
		C -= 1
		result.append('B')
	elif C == 0:
		B -= 1
		C += 1
		result.append('C')
	elif B == 1 and C == 1 and (A == 0) and (i != N - 1):
		if S[i + 1] == 'AB':
			B += 1
			C -= 1
			result.append('B')
		else:
			B -= 1
			C += 1
			result.append('C')
	elif B > C:
		B -= 1
		C += 1
		result.append('C')
	else:
		B += 1
		C -= 1
		result.append('B')
if kekka == False:
	print('No')
else:
	print('Yes')
	for i in range(N):
		print(result[i])


(N, A, B, C) = input().split()
D = dict()
D['A'] = int(A)
D['B'] = int(B)
D['C'] = int(C)
S = []
for i in range(int(N)):
	S.append(input())
ans = 'Yes'
F = []
for (i, s) in enumerate(S):
	if D[s[0]] == 0 and D[s[1]] == 0:
		ans = 'No'
		break
	if D[s[0]] == 1 and D[s[1]] == 1:
		if D['A'] + D['B'] + D['C'] == 2:
			if i != int(N) - 1:
				if S[i + 1] != s:
					s0 = S[i + 1][0]
					s1 = S[i + 1][1]
					if s[0] == s0 or s[0] == s1:
						F.append(s[0])
					if s[1] == s0 or s[1] == s1:
						F.append(s[1])
	if len(F) != i + 1:
		if D[s[0]] < D[s[1]]:
			F.append(s[0])
		if D[s[0]] > D[s[1]]:
			F.append(s[1])
		if D[s[0]] == D[s[1]]:
			F.append(s[0])
	D[F[-1]] += 1
	if s[0] == F[-1]:
		D[s[1]] -= 1
	if s[1] == F[-1]:
		D[s[0]] -= 1
print(ans)
if ans == 'Yes':
	for f in F:
		print(f)


(N, A, B, C) = list(map(int, input().split()))
d = {}
d['A'] = A
d['B'] = B
d['C'] = C
S = [input() for _ in range(N)]
ans = []
for i in range(N):
	s = S[i]
	if s == 'AB':
		if d['A'] > d['B']:
			d['A'] -= 1
			d['B'] += 1
			ans.append('B')
		elif d['A'] < d['B']:
			d['B'] -= 1
			d['A'] += 1
			ans.append('A')
		else:
			if d['A'] == d['B'] == 0:
				print('No')
				return
			if N > i + 1:
				if 'A' in S[i + 1]:
					d['B'] -= 1
					d['A'] += 1
					ans.append('A')
				elif 'B' in S[i + 1]:
					d['A'] -= 1
					d['B'] += 1
					ans.append('B')
				else:
					d['A'] -= 1
					d['B'] += 1
					ans.append('B')
			elif d['A'] > 0:
				ans.append('A')
			elif d['B'] > 0:
				ans.append('B')
	if s == 'AC':
		if d['A'] > d['C']:
			d['A'] -= 1
			d['C'] += 1
			ans.append('C')
		elif d['A'] < d['C']:
			d['C'] -= 1
			d['A'] += 1
			ans.append('A')
		else:
			if d['A'] == d['C'] == 0:
				print('No')
				return
			if N > i + 1:
				if 'A' in S[i + 1]:
					d['C'] -= 1
					d['A'] += 1
					ans.append('A')
				elif 'C' in S[i + 1]:
					d['A'] -= 1
					d['C'] += 1
					ans.append('C')
				else:
					d['A'] -= 1
					d['C'] += 1
					ans.append('C')
			elif d['A'] > 0:
				ans.append('A')
			elif d['C'] > 0:
				ans.append('C')
	if s == 'BC':
		if d['B'] > d['C']:
			d['B'] -= 1
			d['C'] += 1
			ans.append('C')
		elif d['B'] < d['C']:
			d['C'] -= 1
			d['B'] += 1
			ans.append('B')
		else:
			if d['B'] == d['C'] == 0:
				print('No')
				return
			if N > i + 1:
				if 'B' in S[i + 1]:
					d['C'] -= 1
					d['B'] += 1
					ans.append('B')
				elif 'C' in S[i + 1]:
					d['B'] -= 1
					d['C'] += 1
					ans.append('C')
				else:
					d['B'] -= 1
					d['C'] += 1
					ans.append('C')
			elif d['B'] > 0:
				ans.append('B')
			elif d['C'] > 0:
				ans.append('C')
	if -1 in list(d.values()):
		print('No')
		return
print('Yes')
for a in ans:
	print(a)


def main():
	(n, a, b, c) = map(int, input().split())
	Ss = [input() for _ in range(n)]
	ans = []
	f = True
	if a + b + c == 0:
		print('No')
	elif a + b + c == 1:
		for i in range(n):
			if Ss[i] == 'AB':
				if a == 0 and b == 0:
					f = False
					break
				elif a == 1:
					ans.append('B')
					(a, b) = (a - 1, b + 1)
				else:
					ans.append('A')
					(a, b) = (a + 1, b - 1)
			elif Ss[i] == 'AC':
				if a == 0 and c == 0:
					f = False
					break
				elif a == 1:
					ans.append('C')
					(a, c) = (a - 1, c + 1)
				else:
					ans.append('A')
					(a, c) = (a + 1, c - 1)
			elif b == 0 and c == 0:
				f = False
				break
			elif b == 1:
				ans.append('C')
				(b, c) = (b - 1, c + 1)
			else:
				ans.append('B')
				(b, c) = (b + 1, c - 1)
		if f:
			print('Yes')
			for v in ans:
				print(v)
		else:
			print('No')
	else:
		for i in range(n):
			if Ss[i] == 'AB':
				if a == 0 and b == 0:
					f = False
					break
				elif i < n - 1:
					if Ss[i + 1] == 'AB':
						if b == 0:
							ans.append('B')
							(a, b) = (a - 1, b + 1)
						else:
							ans.append('A')
							(a, b) = (a + 1, b - 1)
					elif Ss[i + 1] == 'AC':
						if b == 0:
							ans.append('B')
							(a, b) = (a - 1, b + 1)
						else:
							ans.append('A')
							(a, b) = (a + 1, b - 1)
					elif a == 0:
						ans.append('A')
						(a, b) = (a + 1, b - 1)
					else:
						ans.append('B')
						(a, b) = (a - 1, b + 1)
				elif a == 0 and b == 0:
					f = False
					break
				elif b == 0:
					ans.append('B')
					(a, b) = (a - 1, b + 1)
				else:
					ans.append('A')
					(a, b) = (a + 1, b - 1)
			elif Ss[i] == 'AC':
				if a == 0 and c == 0:
					f = False
					break
				elif i < n - 1:
					if Ss[i + 1] == 'AB':
						if c == 0:
							ans.append('C')
							(a, c) = (a - 1, c + 1)
						else:
							ans.append('A')
							(a, c) = (a + 1, c - 1)
					elif Ss[i + 1] == 'AC':
						if c == 0:
							ans.append('C')
							(a, c) = (a - 1, c + 1)
						else:
							ans.append('A')
							(a, c) = (a + 1, c - 1)
					elif a == 0:
						ans.append('A')
						(a, c) = (a + 1, c - 1)
					else:
						ans.append('C')
						(a, c) = (a - 1, c + 1)
				elif a == 0 and c == 0:
					f = False
					break
				elif c == 0:
					ans.append('C')
					(a, c) = (a - 1, c + 1)
				else:
					ans.append('A')
					(a, c) = (a + 1, c - 1)
			elif b == 0 and c == 0:
				f = False
				break
			elif i < n - 1:
				if Ss[i + 1] == 'AB':
					if c == 0:
						ans.append('C')
						(b, c) = (b - 1, c + 1)
					else:
						ans.append('B')
						(b, c) = (b + 1, c - 1)
				elif Ss[i + 1] == 'AC':
					if b == 0:
						ans.append('B')
						(b, c) = (b + 1, c - 1)
					else:
						ans.append('C')
						(b, c) = (b - 1, c + 1)
				elif b == 0:
					ans.append('B')
					(b, c) = (b + 1, c - 1)
				else:
					ans.append('C')
					(b, c) = (b - 1, c + 1)
			elif b == 0 and c == 0:
				f = False
				break
			elif c == 0:
				ans.append('C')
				(b, c) = (b - 1, c + 1)
			else:
				ans.append('B')
				(b, c) = (b + 1, c - 1)
		if f:
			print('Yes')
			for v in ans:
				print(v)
		else:
			print('No')

def __starting_point():
	main()
__starting_point()


(n, a, b, c) = map(int, input().split())
s = []
for i in range(n):
	si = input()
	s.append(si)
dic = {'A': a, 'B': b, 'C': c}
ans = []
for i in range(n):
	si = s[i]
	(s1, s2) = (si[0], si[1])
	if dic[s1] != dic[s2]:
		if dic[s1] > dic[s2]:
			dic[s1] -= 1
			dic[s2] += 1
			ans.append(s2)
		else:
			dic[s1] += 1
			dic[s2] -= 1
			ans.append(s1)
	elif i == n - 1:
		dic[s1] += 1
		dic[s2] -= 1
		ans.append(s1)
	elif si == s[i + 1]:
		dic[s1] += 1
		dic[s2] -= 1
		ans.append(s1)
	elif s1 in s[i + 1]:
		dic[s1] += 1
		dic[s2] -= 1
		ans.append(s1)
	else:
		dic[s1] -= 1
		dic[s2] += 1
		ans.append(s2)
	if min(dic.values()) < 0:
		print('No')
		exit()
print('Yes')
for i in ans:
	print(i)


(N, A, B, C) = map(int, input().split())
C = {'A': A, 'B': B, 'C': C}
S = [input().strip() for _ in range(N)]
D = []
flag = 0
for i in range(N):
	(a, b) = (S[i][0], S[i][1])
	if C[a] > C[b]:
		C[a] -= 1
		C[b] += 1
		D.append(b)
	elif C[b] > C[a]:
		C[b] -= 1
		C[a] += 1
		D.append(a)
	elif C[a] > 1:
		C[a] -= 1
		C[b] += 1
		D.append(b)
	elif C[a] == 1:
		if i == N - 1:
			D.append(b)
		elif S[i] == S[i + 1]:
			C[a] -= 1
			C[b] += 1
			D.append(b)
		elif a in S[i + 1]:
			C[a] += 1
			C[b] -= 1
			D.append(a)
		else:
			C[a] -= 1
			C[b] += 1
			D.append(b)
	else:
		flag = 1
		break
	if C['A'] < 0 or C['B'] < 0 or C['C'] < 0:
		flag = 1
		break
if flag == 1:
	print('No')
else:
	print('Yes')
	for i in range(N):
		print(D[i])


(n, a, b, c) = list(map(int, input().split()))
if a + b + c == 0:
	print('No')
elif a + b + c == 1:
	d = []
	for i in range(n):
		s = input()
		if s == 'AB':
			if a + b == 0:
				print('No')
				return
			else:
				if a == 0:
					d.append('A')
				else:
					d.append('B')
				(a, b) = (b, a)
		if s == 'BC':
			if c + b == 0:
				print('No')
				return
			else:
				if b == 0:
					d.append('B')
				else:
					d.append('C')
				(c, b) = (b, c)
		if s == 'AC':
			if a + c == 0:
				print('No')
				return
			else:
				if a == 0:
					d.append('A')
				else:
					d.append('C')
				(a, c) = (c, a)
	print('Yes')
	for i in d:
		print(i)
else:
	d = []
	s = [input() for i in range(n)] + ['AB']
	for i in range(n):
		if s[i] == 'AB':
			if a + b == 0:
				print('No')
				return
			if a + b + c == 2 and a == 1 and (b == 1) and (s[i + 1] != s[i]):
				if s[i + 1] == 'AC':
					d.append('A')
					a += 1
					b -= 1
				else:
					d.append('B')
					b += 1
					a -= 1
			elif a < b:
				d.append('A')
				a += 1
				b -= 1
			else:
				d.append('B')
				b += 1
				a -= 1
		elif s[i] == 'BC':
			if c + b == 0:
				print('No')
				return
			if a + b + c == 2 and c == 1 and (b == 1) and (s[i + 1] != s[i]):
				if s[i + 1] == 'AB':
					d.append('B')
					c -= 1
					b += 1
				else:
					d.append('C')
					c += 1
					b -= 1
			elif b < c:
				d.append('B')
				b += 1
				c -= 1
			else:
				d.append('C')
				c += 1
				b -= 1
		elif s[i] == 'AC':
			if c + a == 0:
				print('No')
				return
			if a + b + c == 2 and c == 1 and (a == 1) and (s[i + 1] != s[i]):
				if s[i + 1] == 'AB':
					d.append('A')
					a += 1
					c -= 1
				else:
					d.append('C')
					c += 1
					a -= 1
			elif a < c:
				d.append('A')
				a += 1
				c -= 1
			else:
				d.append('C')
				c += 1
				a -= 1
	print('Yes')
	for i in d:
		print(i)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import time, random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	(n, a, b, c) = LI()
	t = [a, b, c]
	q = [S() for _ in range(n)] + ['ABC']
	r = []
	for qi in range(n):
		s = q[qi]
		if s == 'AB':
			i = 0
			j = 1
		elif s == 'AC':
			i = 0
			j = 2
		else:
			i = 1
			j = 2
		if t[i] < t[j]:
			r.append(i)
			t[i] += 1
			t[j] -= 1
		elif t[i] > t[j]:
			r.append(j)
			t[i] -= 1
			t[j] += 1
		else:
			if t[i] < 1:
				return 'No'
			if chr(ord('A') + i) in q[qi + 1]:
				r.append(i)
				t[i] += 1
				t[j] -= 1
			else:
				r.append(j)
				t[i] -= 1
				t[j] += 1
	return JA(['Yes'] + list(map(lambda x: chr(ord('A') + x), r)), '\n')
print(main())


import sys
readline = sys.stdin.readline
(N, A, B, C) = list(map(int, readline().split()))
S = [readline().rstrip() for i in range(N)]
ans = []
for i in range(N):
	if S[i] == 'AB':
		if A == 0 and B == 0:
			print('No')
			return
		if A < B:
			ans += ['A']
			A += 1
			B -= 1
		elif A > B:
			ans += ['B']
			B += 1
			A -= 1
		elif i + 1 < N and 'A' in S[i + 1]:
			ans += ['A']
			A += 1
			B -= 1
		else:
			ans += ['B']
			B += 1
			A -= 1
	if S[i] == 'AC':
		if A == 0 and C == 0:
			print('No')
			return
		if A < C:
			ans += ['A']
			A += 1
			C -= 1
		elif A > C:
			ans += ['C']
			C += 1
			A -= 1
		elif i + 1 < N and 'A' in S[i + 1]:
			ans += ['A']
			A += 1
			C -= 1
		else:
			ans += ['C']
			C += 1
			A -= 1
	if S[i] == 'BC':
		if B == 0 and C == 0:
			print('No')
			return
		if B < C:
			ans += ['B']
			B += 1
			C -= 1
		elif B > C:
			ans += ['C']
			C += 1
			B -= 1
		elif i + 1 < N and 'B' in S[i + 1]:
			ans += ['B']
			B += 1
			C -= 1
		else:
			ans += ['C']
			C += 1
			B -= 1
print('Yes')
for a in ans:
	print(a)


(n, a, b, c) = map(int, input().split())
s = list((input() for i in range(n))) + ['XX']
ans = ['Yes']
if a + b + c == 0:
	del ans[:]
	ans += ['No']
if a + b + c == 1:
	for j in range(n):
		if s[j] == 'AB':
			if c == 1:
				del ans[:]
				ans += ['No']
				break
			elif a == 1:
				a -= 1
				b += 1
				ans += ['B']
			elif b == 1:
				a += 1
				b -= 1
				ans += ['A']
		if s[j] == 'AC':
			if b == 1:
				del ans[:]
				ans += ['No']
				break
			elif a == 1:
				a -= 1
				c += 1
				ans += ['C']
			elif c == 1:
				a += 1
				c -= 1
				ans += ['A']
		if s[j] == 'BC':
			if a == 1:
				del ans[:]
				ans += ['No']
				break
			elif b == 1:
				b -= 1
				c += 1
				ans += 'C'
			elif c == 1:
				b += 1
				c -= 1
				ans += ['B']
if a + b + c == 2:
	for j in range(n):
		if s[j] == 'AB':
			if a == 2:
				a -= 1
				b += 1
				ans += ['B']
			elif b == 2:
				a += 1
				b -= 1
				ans += ['A']
			elif c == 2:
				del ans[:]
				ans += ['No']
				break
			elif (a == 1 and b == 1) and (s[j + 1] == 'AB' or s[j + 1] == 'AC' or s[j + 1] == 'XX'):
				a += 1
				b -= 1
				ans += ['A']
			elif (a == 1 and b == 1) and s[j + 1] == 'BC':
				a -= 1
				b += 1
				ans += ['B']
			elif a == 1 and c == 1:
				a -= 1
				b += 1
				ans += ['B']
			elif b == 1 and c == 1:
				a += 1
				b -= 1
				ans += ['A']
		if s[j] == 'AC':
			if a == 2:
				a -= 1
				c += 1
				ans += ['C']
			elif c == 2:
				a += 1
				c -= 1
				ans += ['A']
			elif b == 2:
				del ans[:]
				ans += ['No']
				break
			elif (a == 1 and c == 1) and (s[j + 1] == 'AB' or s[j + 1] == 'AC' or s[j + 1] == 'XX'):
				a += 1
				c -= 1
				ans += ['A']
			elif (a == 1 and c == 1) and s[j + 1] == 'BC':
				a -= 1
				c += 1
				ans += ['C']
			elif a == 1 and b == 1:
				a -= 1
				c += 1
				ans += ['C']
			elif b == 1 and c == 1:
				a += 1
				c -= 1
				ans += ['A']
		if s[j] == 'BC':
			if c == 2:
				c -= 1
				b += 1
				ans += ['B']
			elif b == 2:
				c += 1
				b -= 1
				ans += ['C']
			elif a == 2:
				del ans[:]
				ans += ['No']
				break
			elif (c == 1 and b == 1) and (s[j + 1] == 'AB' or s[j + 1] == 'BC' or s[j + 1] == 'XX'):
				b += 1
				c -= 1
				ans += ['B']
			elif (c == 1 and b == 1) and s[j + 1] == 'AC':
				b -= 1
				c += 1
				ans += ['C']
			elif a == 1 and c == 1:
				c -= 1
				b += 1
				ans += ['B']
			elif b == 1 and a == 1:
				c += 1
				b -= 1
				ans += ['C']
if a + b + c >= 3:
	if s[0] == 'AB' and a + b == 0 or (s[0] == 'AC' and a + c == 0) or (s[0] == 'BC' and b + c == 0):
		del ans[:]
		ans += ['No']
	else:
		for j in range(n):
			if s[j] == 'AB':
				if a > b:
					a -= 1
					b += 1
					ans += ['B']
				elif a <= b:
					a += 1
					b -= 1
					ans += ['A']
			if s[j] == 'AC':
				if a > c:
					a -= 1
					c += 1
					ans += ['C']
				elif a <= c:
					a += 1
					c -= 1
					ans += ['A']
			if s[j] == 'BC':
				if b > c:
					b -= 1
					c += 1
					ans += ['C']
				elif b <= c:
					b += 1
					c -= 1
					ans += ['B']
for an in ans:
	print(an)


(n, a, b, c) = map(int, input().split())
abc = list((a, b, c))
ans = [0] * n
dic = {'A': 0, 'B': 1, 'C': 2}
flag = True
s = [input() for i in range(n)]
for i in range(n):
	if abc[dic[s[i][0]]] == 0 and abc[dic[s[i][1]]] == 0:
		flag = False
		break
	elif sum(abc) == 2 and abc[dic[s[i][0]]] == 1 and (abc[dic[s[i][1]]] == 1) and (i != n - 1):
		ps = (set(s[i]) & set(s[i + 1])).pop()
		ms = (set(s[i]) - set(ps)).pop()
		abc[dic[ps]] += 1
		abc[dic[ms]] -= 1
		ans[i] = ps
	elif abc[dic[s[i][0]]] <= abc[dic[s[i][1]]]:
		abc[dic[s[i][0]]] += 1
		abc[dic[s[i][1]]] -= 1
		ans[i] = s[i][0]
	else:
		abc[dic[s[i][0]]] -= 1
		abc[dic[s[i][1]]] += 1
		ans[i] = s[i][1]
if flag:
	print('Yes')
	print(*ans, sep='\n')
else:
	print('No')


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')


import sys
input = sys.stdin.readline
(N, A, B, C) = map(int, input().split())
res = [''] * N
ab = []
ac = []
bc = []

def no():
	print('No')
	exit(0)
for i in range(N):
	s = input()[:-1]
	if s == 'AB':
		ab.append(i)
		A -= 1
		B -= 1
		if A < 0:
			if len(ac):
				A += 2
				res[ac.pop()] = 'A'
			elif len(ab):
				A += 2
				res[ab.pop()] = 'A'
		if B < 0:
			if len(bc):
				B += 2
				res[bc.pop()] = 'B'
			elif len(ab):
				B += 2
				res[ab.pop()] = 'B'
	if s == 'AC':
		ac.append(i)
		A -= 1
		C -= 1
		if A < 0:
			if len(ab):
				A += 2
				res[ab.pop()] = 'A'
			elif len(ac):
				A += 2
				res[ac.pop()] = 'A'
		if C < 0:
			if len(bc):
				C += 2
				res[bc.pop()] = 'C'
			elif len(ac):
				C += 2
				res[ac.pop()] = 'C'
	if s == 'BC':
		bc.append(i)
		B -= 1
		C -= 1
		if B < 0:
			if len(ab):
				B += 2
				res[ab.pop()] = 'B'
			elif len(bc):
				B += 2
				res[bc.pop()] = 'B'
		if C < 0:
			if len(ac):
				C += 2
				res[ac.pop()] = 'C'
			elif len(bc):
				C += 2
				res[bc.pop()] = 'C'
	if min(A, B, C) < 0:
		no()
for x in ab:
	res[x] = 'A'
for x in ac:
	res[x] = 'A'
for x in bc:
	res[x] = 'B'
print('Yes')
for r in res:
	print(r)


import sys
input = sys.stdin.readline

def select_a(a, b):
	nums[a] += 1
	nums[b] -= 1
	choices.append(a)
(n, a, b, c) = map(int, input().split())
nums = [a, b, c]
queries = []
for i in range(n):
	s = input()
	if 'AB' in s:
		queries.append((0, 1))
	elif 'AC' in s:
		queries.append((0, 2))
	else:
		queries.append((1, 2))
choices = []
for i in range(n):
	(p, q) = queries[i]
	if nums[p] > nums[q]:
		select_a(q, p)
		if min(nums) < 0:
			break
	elif nums[p] < nums[q]:
		select_a(p, q)
		if min(nums) < 0:
			break
	elif i == n - 1:
		select_a(p, q)
		if min(nums) < 0:
			break
	else:
		(v, w) = queries[i + 1]
		if p in {v, w}:
			select_a(p, q)
			if min(nums) < 0:
				break
		else:
			select_a(q, p)
			if min(nums) < 0:
				break
if min(nums) < 0:
	print('No')
else:
	print('Yes')
	for choice in choices:
		print('ABC'[choice])


import sys
(n, a, b, c) = map(int, input().split())
S = [input() for _ in range(n)]
abc = {'A': a, 'B': b, 'C': c}
ans = []
for (i, s) in enumerate(S):
	(u, v) = (s[0], s[1])
	if abc[u] == abc[v] == 0:
		print('No')
		sys.exit()
	elif abc[u] > abc[v]:
		abc[u] -= 1
		abc[v] += 1
		ans.append(v)
	elif abc[u] < abc[v]:
		abc[u] += 1
		abc[v] -= 1
		ans.append(u)
	elif i == n - 1:
		ans.append(u)
	elif u in S[i + 1]:
		abc[u] += 1
		abc[v] -= 1
		ans.append(u)
	elif v in S[i + 1]:
		abc[v] += 1
		abc[u] -= 1
		ans.append(v)
print('Yes')
for ans_ in ans:
	print(ans_)


import sys
input = sys.stdin.readline
(N, A, B, C) = map(int, input().split())
S = [input().rstrip() for i in range(N)]
if A == B == C == 0:
	print('No')
	return
if A + B + C == 1:
	ans = []
	for s in S:
		if s == 'AB' and A + B == 0 or (s == 'AC' and A + C == 0) or (s == 'BC' and B + C == 0):
			print('No')
			return
		if s == 'AB':
			if A < B:
				ans.append('A')
			else:
				ans.append('B')
			(A, B) = (B, A)
		if s == 'AC':
			if A < C:
				ans.append('A')
			else:
				ans.append('C')
			(A, C) = (C, A)
		if s == 'BC':
			if B < C:
				ans.append('B')
			else:
				ans.append('C')
			(B, C) = (C, B)
	print('Yes')
	print(*ans, sep='\n')
else:
	ans = []
	for (i, s) in enumerate(S):
		if s == 'AB' and A + B == 0 or (s == 'AC' and A + C == 0) or (s == 'BC' and B + C == 0):
			print('No')
			return
		if s == 'AB':
			if A == 0:
				ans.append('A')
				A += 1
				B -= 1
			elif B == 0:
				ans.append('B')
				B += 1
				A -= 1
			elif A == B == 1:
				if i == N - 1 or C > 0 or S[i + 1] == 'AB':
					ans.append('A')
					A += 1
					B -= 1
				elif S[i + 1] == 'AC':
					ans.append('A')
					A += 1
					B -= 1
				else:
					ans.append('B')
					B += 1
					A -= 1
			elif A < B:
				ans.append('A')
				A += 1
				B -= 1
			else:
				ans.append('B')
				B += 1
				A -= 1
		if s == 'AC':
			if A == 0:
				ans.append('A')
				A += 1
				C -= 1
			elif C == 0:
				ans.append('C')
				C += 1
				A -= 1
			elif A == C == 1:
				if i == N - 1 or B > 0 or S[i + 1] == 'AC':
					ans.append('C')
					C += 1
					A -= 1
				elif S[i + 1] == 'AB':
					ans.append('A')
					A += 1
					C -= 1
				else:
					ans.append('C')
					C += 1
					A -= 1
			elif C < A:
				ans.append('C')
				C += 1
				A -= 1
			else:
				ans.append('A')
				A += 1
				C -= 1
		if s == 'BC':
			if B == 0:
				ans.append('B')
				B += 1
				C -= 1
			elif C == 0:
				ans.append('C')
				C += 1
				B -= 1
			elif B == C == 1:
				if i == N - 1 or A > 0 or S[i + 1] == 'BC':
					ans.append('B')
					B += 1
					C -= 1
				elif S[i + 1] == 'AB':
					ans.append('B')
					B += 1
					C -= 1
				else:
					ans.append('C')
					C += 1
					B -= 1
			elif B < C:
				ans.append('B')
				B += 1
				C -= 1
			else:
				ans.append('C')
				C += 1
				B -= 1
	print('Yes')
	print(*ans, sep='\n')


import sys
input = sys.stdin.readline
(n, a, b, c) = map(int, input().split())
d = {'A': a, 'B': b, 'C': c}
pl = [input() for _ in range(n)]
res = []
for i in range(n):
	p = pl[i]
	if d[p[0]] == d[p[1]] == 0:
		print('No')
		return
	elif d[p[0]] == 0:
		res.append(p[0])
		d[p[0]] += 1
		d[p[1]] -= 1
	elif d[p[1]] == 0:
		res.append(p[1])
		d[p[0]] -= 1
		d[p[1]] += 1
	elif i == n - 1:
		res.append(p[0])
	elif p[0] in pl[i + 1]:
		res.append(p[0])
		d[p[0]] += 1
		d[p[1]] -= 1
	else:
		res.append(p[1])
		d[p[0]] -= 1
		d[p[1]] += 1
print('Yes')
for p in res:
	print(p)


import sys
sr = lambda : sys.stdin.readline().rstrip()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))

def resolve():
	(N, A, B, C) = lr()
	ABC = [A, B, C]
	ans = []

	def ope(u, v):
		ABC[u] += 1
		ABC[v] -= 1
		ans.append(chr(ord('A') + u))
	q = []
	for i in range(N):
		s = sr()
		if s == 'AB':
			(x, y) = (0, 1)
		elif s == 'AC':
			(x, y) = (0, 2)
		else:
			(x, y) = (1, 2)
		q.append([x, y])
	for i in range(N):
		(x, y) = q[i]
		if ABC[x] == 0 and ABC[y] == 0:
			print('No')
			return
		if ABC[x] == 0:
			ope(x, y)
			continue
		if ABC[y] == 0:
			ope(y, x)
			continue
		if i < N - 1:
			(nx, ny) = q[i + 1]
			if x == nx or x == ny:
				ope(x, y)
				continue
		ope(y, x)
	print('Yes')
	print(*ans, sep='\n')
resolve()


import sys
readline = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 6)
(n, *a) = [int(i) for i in readline().split()]
s = read().split()
dx = {'AB': 0, 'BC': 1, 'AC': 2}
ans = ['Yes']

def dfs(i):
	if i == n:
		print(*ans, sep='\n')
		exit()
	x = dx[s[i]]
	y = (x + 1) % 3
	for j in [x, y]:
		if a[j]:
			ans.append('ABC'[x + y - j])
			a[j] -= 1
			a[x + y - j] += 1
			dfs(i + 1)
			ans.pop()
			a[j] += 1
			a[x + y - j] -= 1
dfs(0)
print('No')