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

n, m = map(int, input().split())
d = list(map(int, input().split()))
adj = [[] for _ in range(n)]
inn = [0 for _ in range(n)]
out = [0 for _ in range(n)]
col = [-1 for _ in range(n)]
ans = [10**9 for _ in range(m)]
for i in range(m):
	u, v = map(int, input().split())
	u, v = u-1, v-1
	if d[u] >= d[v]:
		adj[u].append([v, i])
		inn[v] += 1
		out[u] += 1
	if d[u] <= d[v]:
		adj[v].append([u, i])
		inn[u] += 1
		out[v] += 1
for a in adj:
	a.sort(key=lambda x: d[x[0]])

ok = True
for x in out:
	if x == 0:
		ok = False
		break

if not ok:
	print(-1)
	sys.exit()

if len(set(d)) == 1:
	print("B" + "W" * (n-1))
	print(*([d[0]] * m), sep="\n")
	sys.exit()

nodes = sorted([[x, i] for i, x in enumerate(d)], key=lambda x: -x[0])
#col[nodes[0][1]] = 0

for x, i in nodes:
	if col[i] < 0:
		col[i] = 0
	c = col[i]
	if col[adj[i][0][0]] < 0:
		col[adj[i][0][0]] = 1^c
		ans[adj[i][0][1]] = x

col_str = ["B" if x else "W" for x in col]
#print(col_str)
print("".join(col_str))
print(*ans, sep="\n")