The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this size.

During the registration, the organizers asked each of the n participants about the t-shirt size he wants. If a participant hesitated between two sizes, he could specify two neighboring sizes — this means that any of these two sizes suits him.

Write a program that will determine whether it is possible to present a t-shirt to each participant of the competition, or not. Of course, each participant should get a t-shirt of proper size:   the size he wanted, if he specified one size;  any of the two neibouring sizes, if he specified two sizes. 

If it is possible, the program should find any valid distribution of the t-shirts.


-----Input-----

The first line of the input contains six non-negative integers — the number of t-shirts of each size. The numbers are given for the sizes S, M, L, XL, XXL, XXXL, respectively. The total number of t-shirts doesn't exceed 100 000.

The second line contains positive integer n (1 ≤ n ≤ 100 000) — the number of participants.

The following n lines contain the sizes specified by the participants, one line per participant. The i-th line contains information provided by the i-th participant: single size or two sizes separated by comma (without any spaces). If there are two sizes, the sizes are written in increasing order. It is guaranteed that two sizes separated by comma are neighboring.


-----Output-----

If it is not possible to present a t-shirt to each participant, print «NO» (without quotes).

Otherwise, print n + 1 lines. In the first line print «YES» (without quotes). In the following n lines print the t-shirt sizes the orginizers should give to participants, one per line. The order of the participants should be the same as in the input.

If there are multiple solutions, print any of them.


-----Examples-----
Input
0 1 0 1 1 0
3
XL
S,M
XL,XXL

Output
YES
XL
M
XXL

Input
1 1 2 0 1 1
5
S
M
S,M
XXL,XXXL
XL,XXL

Output
NO

Difficulty: interview

Starter code:

Solutions:
3

szs = ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']
d = {'S':0, 'M':1, 'L':2, 'XL':3, 'XXL':4, 'XXXL':5}
neigh = [[] for i in range(5)]

of = list(map(int, input().split()))
n = int(input())
ans = ['' for i in range(n)]
for i in range(n):
    t = input()
    if ',' in t:
        neigh[d[t.split(',')[0]]].append(i)
    else:
        of[d[t]] -= 1
        ans[i] = t

for i in range(6):
    if of[i] < 0:
        print("NO")
        return
    if i > 0:
        while len(neigh[i - 1]) and of[i] > 0:
            ans[neigh[i - 1][-1]] = szs[i]
            neigh[i - 1].pop()
            of[i] -= 1
    if i < 5:
        while len(neigh[i]) and of[i] > 0:
            ans[neigh[i][-1]] = szs[i]
            neigh[i].pop()
            of[i] -= 1


if sum([len(neigh[i]) for i in range(5)]) != 0:
    print("NO")
else:
    print("YES")
    print("\n".join(ans))


a = list(map(int,input().split()))
b = [0,0,0,0,0];
c = [0,0,0,0,0];
ipt = [];
ans = [];
d = {"S" : 0,"M" : 1, "L" : 2, "XL" : 3, "XXL" : 4, "XXXL" : 5}

n = int(input())

for i in range(1,n+1) :
    j = input()
    ipt.append(j)
    ans.append(j)
    if j.find(',') == -1 :
        a[d[j]] -= 1
    else :
        b[d[j[0:j.find(',')]]] += 1

ans = False;

for i in range(0,6) :
    if (a[i] < 0) and ans == False:
        ans = True
    elif i < 5:
        if i==0 :
            if b[i] > a[i] :
                c[i] = b[i] - a[i];
                b[i] -= a[i];
                a[i] = 0;
            else :
                c[i] = 0;
                a[i] -= b[i];
                b[i] = 0;
                
        else :
            if b[i-1] > 0 :
                if b[i-1] > a[i] :
                    ans = True
                else :
                    a[i] -= b[i-1];
            if b[i] > a[i] :
                c[i] = b[i] - a[i];
                b[i] -= a[i];
                a[i] = 0;
            else :
                c[i] = 0;
                a[i] -= b[i];
                b[i] = 0;
    elif i==5 :
        if a[i] < b[i-1]:
            ans = True
                
if ans == True :
    print("NO");

else :
    print("YES")
    for i in ipt :
        if i.find(',') == -1 :
            print(i)
        else :
            tmp = i[0:i.find(',')];
            if (c[d[tmp]] > 0) :
                print(i[i.find(',')+1:])
                c[d[tmp]] -= 1
            else :
                print(tmp)




shorts = [int(t) for t in input().split()]
n = int(input())
d = dict()
d["S"] = 0
d["M"] = 1
d["L"] = 2
d["XL"] = 3
d["XXL"] = 4
d["XXXL"] = 5
people = []
order = [t for t in range(n)]
for _ in range(n):
    people.append(input().split(","))
order.sort(key=lambda x: [d[people[x][0]], len(people[x])])
ans = dict()
for i in order:
    p = people[i]
    if shorts[d[p[0]]] != 0:
        ans[i] = p[0]
        shorts[d[p[0]]] -= 1
    elif len(p) == 2 and  shorts[d[p[1]]] != 0:
        ans[i] = p[1]
        shorts[d[p[1]]] -= 1
    else:
        print("NO")
        return
print("YES")
for i in ans.keys():
    print(ans[i])

# You lost the game.
import sys
T = list(map(int, input().split()))
L = [[] for _ in range(6)]
D = [[] for _ in range(5)]
n = int(input())
S = [str(input()) for _ in range(n)]
for i in range(n):
    x = list(S[i].split(","))
    if len(x) == 2:
        if x[0] == "S":
            D[0] += [i]
        if x[0] == "M":
            D[1] += [i]
        if x[0] == "L":
            D[2] += [i]
        if x[0] == "XL":
            D[3] += [i]
        if x[0] == "XXL":
            D[4] += [i]
        if x[0] == "XXXL":
            D[5] += [i]
    else:
        if x[0] == "S":
            L[0] += [i]
        if x[0] == "M":
            L[1] += [i]
        if x[0] == "L":
            L[2] += [i]
        if x[0] == "XL":
            L[3] += [i]
        if x[0] == "XXL":
            L[4] += [i]
        if x[0] == "XXXL":
            L[5] += [i]
a = 0
ok = 1
R = ["" for _ in range(n)]

# S
if len(L[0]) <= T[0]:
    for x in L[0]:
        R[x] = "S"
    T[0] -= len(L[0])
else:
    print("NO")
    ok = 0
    
a = max(0,len(D[0]) - T[0])
for i in range(min(len(D[0]),T[0])):
    R[D[0][i]] = "S"

# M
if a+len(L[1]) <= T[1]:
    for i in range(len(D[0])-a,len(D[0])):
        R[D[0][i]] = "M"
    for x in L[1]:
        R[x] = "M"
    T[1] -= len(L[1])+a
else:
    print("NO")
    ok = 0
    
a = max(0,len(D[1]) - T[1])
for i in range(min(len(D[1]),T[1])):
    R[D[1][i]] = "M"

# L
if a+len(L[2]) <= T[2]:
    for i in range(len(D[1])-a,len(D[1])):
        R[D[1][i]] = "L"
    for x in L[2]:
        R[x] = "L"
    T[2] -= len(L[2])+a
else:
    print("NO")
    ok = 0
    
a = max(0,len(D[2]) - T[2])
for i in range(min(len(D[2]),T[2])):
    R[D[2][i]] = "L"

# XL
if a+len(L[3]) <= T[3]:
    for i in range(len(D[2])-a,len(D[2])):
        R[D[2][i]] = "XL"
    for x in L[3]:
        R[x] = "XL"
    T[3] -= len(L[3])+a
else:
    print("NO")
    ok = 0
    
a = max(0,len(D[3]) - T[3])
for i in range(min(len(D[3]),T[3])):
    R[D[3][i]] = "XL"

# XXL
if a+len(L[4]) <= T[4]:
    for i in range(len(D[3])-a,len(D[3])):
        R[D[3][i]] = "XXL"
    for x in L[4]:
        R[x] = "XXL"
    T[4] -= len(L[4])+a
else:
    print("NO")
    ok = 0
    
a = max(0,len(D[4]) - T[4])
for i in range(min(len(D[4]),T[4])):
    R[D[4][i]] = "XXL"

# XXXL
if a+len(L[5]) <= T[5]:
    for i in range(len(D[4])-a,len(D[4])):
        R[D[4][i]] = "XXXL"
    for x in L[5]:
        R[x] = "XXXL"
else:
    print("NO")
    ok = 0

if ok:
    print("YES")
    for i in range(n):
        print(R[i])



arr = list(map(int, input().split()))
n = int(input())
d = {'S' : 0, 'M' : 1, 'L' : 2, 'XL' : 3, 'XXL' : 4, 'XXXL' : 5, 0:'S', 1:'M', 2:'L', 3:'XL', 4:'XXL', 5:'XXXL'}
ans = [-1] * n
fl = False
men = []
for i in range(n):
    s = input().split(',')
    if len(s) == 1:
        if arr[d[s[0]]] != 0:
            arr[d[s[0]]] -= 1
            ans[i] = s[0]
        else:
            print('NO')
            fl = True
    else:
        men.append((d[s[0]], d[s[1]], i))
if not fl:    
    men.sort()
    #print(men)
    for i in range(len(men)):
        if arr[men[i][0]] != 0:
            arr[men[i][0]] -= 1
            ans[men[i][-1]] = d[men[i][0]]
            continue
        elif len(men[i]) == 2:
            print('NO')
            fl = True
            break
        elif arr[men[i][1]] != 0:
            arr[men[i][1]] -= 1
            ans[men[i][-1]] = d[men[i][1]]
            continue
        else:
            print('NO')
            fl = True
            break   
        
    if not fl:
        print('YES')
        print('\n'.join(ans))

d = {"S": 0, "M" : 1, "L" : 2, "XL" : 3, "XXL" : 4, "XXXL" : 5}
nums = list(map(int, input().split()))
n = int(input())
ans = ['' for i in range(n)]
no = []
for i in range(n):
	x = input().split(',')
	if len(x) > 1:
		no.append(x + [i])
	else:
		nums[d[x[0]]] -= 1
		ans[i] = x[0]
for i in range(6):
	if nums[i] < 0:
		print("NO")
		return
no.sort(key = lambda x: d[x[0]])
for item in no:
	if nums[d[item[0]]] > 0:
		ans[item[2]] = item[0]
		nums[d[item[0]]] -= 1
	elif nums[d[item[1]]] > 0:
		ans[item[2]] = item[1]
		nums[d[item[1]]] -= 1
	else:
		print("NO")
		return
print("YES")
for i in ans:
	print(i)

from collections import defaultdict

dist = list(map(int, input().split()))

a = [0] * 11

indexes = {'S':0, 'M':1, 'L':2, 'XL':3, 'XXL':4, 'XXXL':5, 'S,M':6, 'M,L':7, 'L,XL':8, 'XL,XXL':9, 'XXL,XXXL':10}
inv = dict(list(zip(list(indexes.values()), list(indexes.keys()))))

n = int(input())

par_d = defaultdict(list)

par = [None] * n

for i in range(n):
    ind = indexes[input().strip()]

    if ind <= 5:
        dist[ind] -= 1
        par[i] = ind
    else:
        par_d[ind].append(i)

    a[ind] += 1

if min(dist) < 0:
    print("NO")
    return

k = 0
k_p = []

for i in range(6, 11):
    size = i - 6

    dist[size] -= k
    if dist[size] < 0:
        print("NO")
        return
    else:
        for j in k_p:
            par[j] = size

    m = len(par_d[i])

    if dist[size] + dist[size+1] < m:
        print("NO")
        return

    if dist[size] <= m:
        p = par_d[i][:dist[size]]
        k_p = par_d[i][dist[size]:]

        k = m - dist[size]
        for j in p:
            par[j] = size
        dist[size] = 0

    else:
        p = par_d[i]
        k_p = []

        k = 0
        for j in p:
            par[j] = size

if k > dist[-1]:
    print("NO")
    return

else:
    for j in k_p:
        par[j] = 5


print('YES')
for i in range(n):
    print(inv[par[i]])


d = {}
d["S"] = 0
d["M"] = 1
d["L"] = 2
d["XL"] = 3
d["XXL"] = 4
d["XXXL"] = 5

cnt = [int(t) for t in input().split()]
n = int(input())
ind = [i for i in range(n)]
p = []
for i in range(n):
    p.append(input().split(','))
ind.sort(key=lambda x:[d[p[x][0]], len(p[x])])
ans = {}
for i in ind:
    cur = p[i]
    if cnt[d[cur[0]]] != 0:
        ans[i] = cur[0]
        cnt[d[cur[0]]] -= 1
    elif len(cur) == 2 and cnt[d[cur[1]]] != 0:
        ans[i] = cur[1]
        cnt[d[cur[1]]] -= 1
    else:
        print("NO")
        return
print("YES")
for i in list(ans.keys()):
    print(ans[i])



__author__ = 'Think'
assign={"S":0, "M":1, "L":2, "XL":3, "XXL":4, "XXXL":5, "S,M":6, "M,L":7, "L,XL":8, "XL,XXL":9, "XXL,XXXL":10}
up={"S,M":"M", "M,L":"L", "L,XL":"XL", "XL,XXL":"XXL", "XXL,XXXL":"XXXL"}
down={"S,M":"S", "M,L":"M", "L,XL":"L", "XL,XXL":"XL", "XXL,XXXL":"XXL"}
shirts={i:0 for i in range(11)}
numbers=[int(i) for i in input().split()]
split={i:0 for i in range(6, 11)}
n=int(input())
failed=False
received=[]
for i in range(n):
	s=input()
	shirts[assign[s]]+=1
	received.append(s)
for i in range(6):
	numbers[i]-=shirts[i]
	if numbers[i]<0:
		print("NO")
		failed=True
		break
if not failed:
	for i in range(6, 11):
		below=numbers[i-6]
		above=numbers[i-5]
		needed=shirts[i]
		if below>=needed:
			split[i]=needed
		else:
			split[i]=below
			needed-=below
			if above<needed:
				failed=True
				print("NO")
				break
			else:
				numbers[i-5]-=needed
	if not failed:
		print("YES")
		for s in received:
			if assign[s]<6:
				print(s)
			else:
				if split[assign[s]]>0:
					split[assign[s]]-=1
					print(down[s])
				else:
					print(up[s])


TShirts = list(map(int, input().split()))
NPers = int(input())
Needs = [0,0,0,0,0]
T = [0 for i in range(10)]
Pers = []
IsFound = True

if sum(TShirts) < NPers:
    IsFound = False

for i in range(NPers):
    s = input().split(',')
    Pers.append(0)
    if 'S' in s:
        Pers[-1] += 1
    if 'M' in s:
        Pers[-1] += 2
    if 'L' in s:
        Pers[-1] += 4
    if 'XL' in s:
        Pers[-1] += 8
    if 'XXL' in s:
        Pers[-1] += 16
    if 'XXXL' in s:
        Pers[-1] += 32

for i in Pers:
    if i==1 :
        TShirts[0] -= 1
    elif i==2 :
        TShirts[1] -= 1
    elif i==4 :
        TShirts[2] -= 1
    elif i==8 :
        TShirts[3] -= 1
    elif i==16 :
        TShirts[4] -= 1
    elif i==32 :
        TShirts[5] -= 1

for i in TShirts:
    if i < 0 and IsFound:
        IsFound = False

for i in Pers:
    if (i&1!=0) and (i&2!=0):
        Needs[0] += 1
    elif (i & 2!=0) and (i & 4!=0):
        Needs[1] += 1
    elif (i & 4!=0) and (i & 8!=0):
        Needs[2] += 1
    elif (i & 8!=0) and (i & 16!=0):
        Needs[3] += 1
    elif (i & 16!=0) and (i & 32!=0):
        Needs[4] += 1


for i in range(5):
    while Needs[i] > 0 and TShirts[i]>0:
        Needs[i] -= 1
        TShirts[i] -= 1
        T[2*i] += 1
    while Needs[i] > 0 and TShirts[i+1] > 0:
        Needs[i] -= 1
        TShirts[i+1] -= 1
        T[2*i + 1] += 1

if sum(Needs) > 0:
    IsFound = False

if IsFound:
    print('YES')

    for i in range(len(Pers)):
        if T[0] > 0 and Pers[i] == 3:
            Pers[i] -= Pers[i] - 1
            T[0] -= 1
        elif T[1] > 0 and Pers[i] == 3:
            Pers[i] -= Pers[i] - 2
            T[1] -= 1
    for i in range(len(Pers)):
        if T[2] > 0 and Pers[i] == 6:
            Pers[i] -= Pers[i] - 2
            T[2] -= 1
        elif T[3] > 0 and Pers[i] == 6:
            Pers[i] -= Pers[i] - 4
            T[3] -= 1
    for i in range(len(Pers)):
        if T[4] > 0 and Pers[i] == 12:
            Pers[i] -= Pers[i] - 4
            T[4] -= 1
        elif T[5] > 0 and Pers[i] == 12:
            Pers[i] -= Pers[i] - 8
            T[5] -= 1
    for i in range(len(Pers)):
        if T[6] > 0 and Pers[i] == 24:
            Pers[i] -= Pers[i] - 8
            T[6] -= 1
        elif T[7] > 0 and Pers[i] == 24:
            Pers[i] -= Pers[i] - 16
            T[7] -= 1
    for i in range(len(Pers)):
        if T[8] > 0 and Pers[i] == 48:
            Pers[i] -= Pers[i] - 16
            T[8] -= 1
        elif T[9] > 0 and Pers[i] == 48:
            Pers[i] -= Pers[i] - 32
            T[9] -= 1

    for i in Pers:
        if i & 1:
            print('S')
        elif i & 2:
            print('M')
        elif i & 4:
            print('L')
        elif i & 8:
            print('XL')
        elif i & 16:
            print('XXL')
        elif i & 32:
            print('XXXL')
else:
    print('NO')

def solve(a, n):
    M={'S':0, 'M':1, 'L':2, 'XL':3, 'XXL':4, 'XXXL':5}
    m={0:'S', 1:'M', 2:'L', 3:'XL', 4:'XXL', 5:'XXXL'}
    p=[ [] for _ in range(5) ]
    ans=['']*n
    for i in range(n):
        s=input()
        if ',' in s:
            p[ M[ s[:s.find(',')] ] ]+=[i]
        else:
            s=M[s]
            if a[s]<=0:
                return []
            a[s]-=1
            ans[i]=m[s]
    for i in range(5):
        for x in p[i]:
            if a[i]>0:
                a[i]-=1
                ans[x]=m[i]
            elif a[i+1]>0:
                a[i+1]-=1
                ans[x]=m[i+1]
            else:
                return []
    return ans
ans=solve(list(map(int, input().split())), int(input()))
if ans==[]:
    print('NO')
else:
    print('YES')
    for s in ans:
        print(s)

counts = [int(x) for x in input().split()]
n = int(input())
sizes = ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']
size_to_i = {size:i for i, size in enumerate(sizes)}
two_sizes = {(x,y): [] for x, y in zip(list(range(6)), list(range(1, 7)))}

decision = [''] * n

for i in range(n):
    demand = [size_to_i[size] for size in input().split(',')]
    if len(demand) == 1:
        d = demand[0]
        counts[d] -= 1
        decision[i] = sizes[d]
    else:
        two_sizes[(demand[0], demand[1])].append(i)

for smaller, larger in zip(list(range(5)), list(range(1, 6))):
    for part in two_sizes[(smaller, larger)]:
        to_give = smaller if counts[smaller] > 0 else larger
        counts[to_give] -= 1
        decision[part] = sizes[to_give]

def possible():
    for c in counts:
        if c < 0:
            return False
    return True

if possible():
    print('YES')
    for d in decision:
        print(d)
else:
    print('NO')



d={"S":0,"M":1,"L":2,"XL":3,"XXL":4,"XXXL":5}
cnt=[int(t) for t in input().split()]
n=int(input())
ind=[i for i in range(n)]
p=[]
for i in range(n):p.append(input().split(','))
ind.sort(key=lambda x:[d[p[x][0]], len(p[x])])
ans={}
for i in ind:
	cur=p[i]
	if cnt[d[cur[0]]]!=0:
		ans[i]=cur[0]
		cnt[d[cur[0]]]-=1
	elif len(cur)==2 and cnt[d[cur[1]]]!=0:
		ans[i]=cur[1]
		cnt[d[cur[1]]]-=1
	else:
		print("NO")
		return
print("YES")
for i in list(ans.keys()):print(ans[i])


tsh = list(map(int, input().split()))
need = [[0, 0] for i in range(6)]
n = int(input())
ans = [[0, False] for i in range(n)]
for i in range(n):
    req = input().split(",")
    ans[i][1] = len(req) > 1
    if len(req) == 1:
        if req[0] == 'S':
            need[0][0] += 1
            ans[i][0] = 0
        elif req[0] == 'M':
            need[1][0] += 1
            ans[i][0] = 1
        elif req[0] == 'L':
            need[2][0] += 1
            ans[i][0] = 2
        elif req[0] == 'XL':
            need[3][0] += 1
            ans[i][0] = 3
        elif req[0] == 'XXL':
            need[4][0] += 1
            ans[i][0] = 4
        elif req[0] == 'XXXL':
            need[5][0] += 1
            ans[i][0] = 5
    else:
        if req[0] == 'S':
            need[0][1] += 1
            ans[i][0] = 0
        elif req[0] == 'M':
            need[1][1] += 1
            ans[i][0] = 1
        elif req[0] == 'L':
            need[2][1] += 1
            ans[i][0] = 2
        elif req[0] == 'XL':
            need[3][1] += 1
            ans[i][0] = 3
        elif req[0] == 'XXL':
            need[4][1] += 1
            ans[i][0] = 4
        elif req[0] == 'XXXL':
            need[5][1] += 1
            ans[i][0] = 5
next = 0
new = [[0, 0] for i in range(6)]
for i in range(6):
    tsh[i] -= need[i][0]
    tsh[i] -= next
    new[i][0] = next + need[i][0]
    if tsh[i] < 0:
        print("NO"); quit()
    can = min(tsh[i], need[i][1])
    next = need[i][1] - can
    new[i][1] = next
print("YES")
for x in ans:
    if x[1] and new[x[0]][1] > 0:
        new[x[0]][1] -= 1
        x[0] += 1
    t = x[0]
    if t == 0:
        print("S")
    elif t == 1:
        print("M")
    elif t == 2:
        print("L")
    elif t == 3:
        print("XL")
    elif t == 4:
        print("XXL")
    elif t == 5:
        print("XXXL")

d = {"S": 0, "M": 1, "L":2,"XL":3,"XXL":4,"XXXL":5}

cnt = [int(t) for t in input().split()]
n = int(input())
ind = [i for i in range(n)]
p = []
for i in range(n):
    p.append(input().split(','))
ind.sort(key=lambda x:[d[p[x][0]], len(p[x])])
ans = {}
for i in ind:
    cur = p[i]
    if cnt[d[cur[0]]] != 0:
        ans[i] = cur[0]
        cnt[d[cur[0]]] -= 1
    elif len(cur) == 2 and cnt[d[cur[1]]] != 0:
        ans[i] = cur[1]
        cnt[d[cur[1]]] -= 1
    else:
        print("NO")
        return
print("YES")
for i in ans.keys():
    print(ans[i])

d = dict.fromkeys(['S', 'M', 'L', 'XL', 'XXL', 'XXXL'])
d2 = {'S': 0, 'M': 0, 'L': 0, 'XL': 0, 'XXL': 0}
d3 = {'S': 0, 'M': 0, 'L': 0, 'XL': 0, 'XXL': 0, 'XXXL': 0}
l = input().split()
l2 = []
i = 0
for x in ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']:
  d[x] = int(l[i])
  i += 1

n = int(input())
t = True
for i in range(n):
  l = input().split(',')
  l2 += [l]
  if len(l) == 1:
    d[l[0]] -= 1
    if d[l[0]] < 0:
      print('NO')
      t = False
      break
  else:
    d2[l[0]] += 1
m = ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']
if t == True:    
  for i in range(5):
    if d[m[i]] >= d2[m[i]]:
      d3[m[i]] += d2[m[i]]
      d[m[i]] -= d2[m[i]]
    else:
      d3[m[i]] += d[m[i]]
      d[m[i+1]] -= (d2[m[i]] - d[m[i]])
      d[m[i]] = 0
      if d[m[i+1]] < 0:
        print('NO')
        t = False
        break
if t == True:
  print('YES')
  for x in l2:
    if len(x) == 1:
      print(x[0])
    else:
      if d3[x[0]] > 0:
        print(x[0])
        d3[x[0]] -= 1
      else:
        print(x[1])

d = dict.fromkeys(['S', 'M', 'L', 'XL', 'XXL', 'XXXL'])
d2 = {'S': 0, 'M': 0, 'L': 0, 'XL': 0, 'XXL': 0}
d3 = {'S': 0, 'M': 0, 'L': 0, 'XL': 0, 'XXL': 0, 'XXXL': 0}
l = input().split()
l2 = []
i = 0
for x in ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']:
  d[x] = int(l[i])
  i += 1

n = int(input())
t = True
for i in range(n):
  l = input().split(',')
  l2 += [l]
  if len(l) == 1:
    d[l[0]] -= 1
    if d[l[0]] < 0:
      print('NO')
      t = False
      break
  else:
    d2[l[0]] += 1
m = ['S', 'M', 'L', 'XL', 'XXL', 'XXXL']
if t == True:    
  for i in range(5):
    if d[m[i]] >= d2[m[i]]:
      d3[m[i]] += d2[m[i]]
      d[m[i]] -= d2[m[i]]
    else:
      d3[m[i]] += d[m[i]]
      d[m[i+1]] -= (d2[m[i]] - d[m[i]])
      d[m[i]] = 0
      if d[m[i+1]] < 0:
        print('NO')
        t = False
        break
if t == True:
  print('YES')
  for x in l2:
    if len(x) == 1:
      print(x[0])
    else:
      if d3[x[0]] > 0:
        print(x[0])
        d3[x[0]] -= 1
      else:
        print(x[1])
      
    
      



shirts_count=list(map(int,input().split()))
no=False
n=0
for i in shirts_count:
   n+=i 
sizes=('S','M','L','XL','XXL','XXXL')
shirts=dict()
children=list()
for i in range(len(sizes)):
    shirts[sizes[i]]=shirts_count[i]
for i in range(int(input())):
    children.append(input().split(','))
if n<len(children):
    print('NO')
else:
    itog=[0]*len(children)
    for i in range(len(children)):
        if len(children[i])==1:
            if shirts[str(children[i][0])]>0:
                shirts[str(children[i][0])]-=1
                itog[i]=str(children[i][0])
            else:
                no=True
    a=0
    while a<5 and not no:
        for i in range(len(children)):
            if len(children[i])>1:
                if sizes[a]==children[i][0] and sizes[a+1]==children[i][1]:
                    if shirts[sizes[a]]>0:
                        itog[i]=sizes[a]
                        shirts[sizes[a]]-=1
                    else:
                        if shirts[sizes[a+1]]>0:
                            itog[i]=sizes[a+1]
                            shirts[sizes[a+1]]-=1
                        else:
                            no=True
        a+=1
    if not no:
        print('YES')
        for i in range(len(itog)):
            print(itog[i])
    if no:
        print('NO')


def distribution(available, wish):
    double_keys = ['S,M', 'M,L', 'L,XL', 'XL,XXL', 'XXL,XXXL']
    double = {key: [] for key in double_keys}
    people = [''] * len(wish)
    for i, w in enumerate(wish):
        if w.count(',') == 0:
            if available[w] > 0:
                available[w] -= 1
                people[i] = w
            else:
                return ['NO']
        else:
            double[w].append(i)

    for key in double_keys:
        for p in double[key]:
            lack = True
            for size in key.split(','):
                if available[size] > 0:
                    available[size] -= 1
                    people[p] = size
                    lack = False
                    break
            if lack:
                return ['NO']
    return ['YES', people]

def stock():
    return {size: amount for size, amount in zip(['S', 'M', 'L', 'XL', 'XXL', 'XXXL'], map(int, input().split()))}

def request():
    return [input() for i in range(int(input()))]

def solution(n):
    return [input() for i in range(n)]

def answer():
    ans = distribution(stock(), request())
    if ans[0] == 'YES':
        print('YES')
        for p in ans[1]:
            print(p)
    else:
        print('NO')

def check(s, l):
    for size in l:
        if size not in s:
            return False
        else:
            s[size] -= 1
            if s[size] < 0:
                return False
    return True

def compare():
    s = stock()
    r = request()
    ans = distribution(s.copy(), r)
    try:
        usr = input()
        if usr == 'YES':
            l = solution(len(r))
        elif usr == 'NO':
            l = []
        else:
            print(0)
            print('Нарушен формат вывода')
            return
    except EOFError:
        print(0)
        print('Нарушен формат вывода')
        return

    if usr != ans[0] or ans[0] == 'YES' and not check(s.copy(), l):
        print(0)
        print('Failed. T-shirts:', s, '. Request:', ';'.join(r), '. Your solution:', usr, ' - ', ';'.join(l))
    else:
        print(1)
        print('Ok')

answer()

contest = True
if not contest:
    fin = open("in", "r")
inp = input if contest else lambda: fin.readline()[:-1]
read = lambda: tuple(map(int, inp().split()))

tz = dict([(v, i) for i, v in enumerate("S,M,L,XL,XXL,XXXL".split(","))])
#print(tz)
sz = list(read())
n = read()[0]
def main():
    ans = {}
    q = []
    for i in range(n):
        v = inp().split(",")
        #print(sz)
        if len(v) == 1:
            v = v[0]
            ans[i] = v
            sz[tz[v]] -= 1
            if sz[tz[v]] < 0:
                return ["NO"]
        else:
            v = sorted([(tz[e], e, i) for e in v], key=lambda v: v[0])
            q += [v]
    q.sort(key=lambda v:v[0][0])
    #print(q)
    for v in q:
        #print(sz, v)
        if sz[v[0][0]] <= 0:
            if sz[v[1][0]] <= 0:
                return ["NO"]
            else:
                sz[v[1][0]] -= 1
                ans[v[1][2]] = v[1][1]
        else:
            sz[v[0][0]] -= 1
            ans[v[0][2]] = v[0][1]
    #print(ans)
    return ["YES", [ans[i] for i in range(n)]]
v = main()
print(v[0])
if len(v) > 1:
    print("\n".join(v[1]))