import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter
from collections import defaultdict

N,M = map(int,readline().split())
D = [0] + list(map(int,readline().split()))
m = map(int,read().split())
UV = list(zip(m,m))

graph = [[] for _ in range(N+1)]
for u,v in UV:
    graph[u].append((v,D[v]))
    graph[v].append((u,D[u]))

subgraph = [[] for _ in range(N+1)]
is_ng = False
for v in range(1,N+1):
    graph[v].sort(key = itemgetter(1))
    w,d = graph[v][0]
    if D[v] < d:
        is_ng = True
        break
    subgraph[w].append(v)

if is_ng:
    print(-1)
    exit()

INF = 10 ** 9
wt_edge = defaultdict(lambda:INF)
color = [0] * (N+1)

# (index, weight), sorted by wt
I = sorted(enumerate(D), key = itemgetter(1))[1:]

for v, wt in I:
    if color[v]:
        continue
    stack = [v]
    color[v] = 1
    v0 = v
    while stack:
        v = stack.pop()
        cw = 3 - color[v]
        for w in subgraph[v]:
            if w == v0:
                continue
            color[w] = cw
            wt_edge[(v,w)] = D[w]
            wt_edge[(w,v)] = D[w]
            stack.append(w)

S = ''.join('B' if x == 1 else 'W' for x in color[1:])
C = [wt_edge[(u,v)] for u,v in UV]

print(S)
print('\n'.join(map(str,C)))