import sys
N, M = map(int, input().split())
D = list(map(int, input().split()))
DI = list(zip(D, list(range(N))))
G = [[] for _ in range(N)]
for i in range(M):
    u, v = map(int, input().split())
    G[u-1].append((v-1, i))
    G[v-1].append((u-1, i))
DI.sort()
V = [-1]*N
j = 0
used = [False]*N
ans = [10**9]*M
BW = ['']*N
for j in range(N):
    d, v = DI[j]
    if used[v]:
        continue
    for nv, i in G[v]:
        if d == D[nv]:
            if BW[nv] == '':
                BW[nv] = 'B'
                BW[v] = 'W'
                ans[i] = d
                used[v] = True
                used[nv] = True
            elif BW[nv] == 'W':
                BW[v] = 'B'
                ans[i] = d
                used[v] = True
            else:
                BW[v] = 'W'
                ans[i] = d
                used[v] = True
            break
        elif used[nv]:
            if BW[nv] == 'B':
                BW[v] = 'W'
                ans[i] = d-D[nv]
            else:
                BW[v] = 'B'
                ans[i] = d-D[nv]
    if not used[v]:
        print(-1)
        sys.exit()
print(*BW, sep = '')
print(*ans, sep = '\n')
