n, m = map(int, input().split())
d = list(map(int, input().split()))
edge = [[] for i in range(n)]
INF = 10**9
cost = [INF] * m
done = [False] * n

for i in range(m):
    u, v = map(int, input().split())
    u-=1
    v-=1
    edge[u].append((v,i))
    edge[v].append((u,i))
    cost[i] = max(d[u], d[v])

color = [0] * n
   
def dfs(now, col = 0):
    done[now] = True
    color[now] = col
    ok = False
    for (to,i) in edge[now]:
        if cost[i] == d[now]:
            ok = True
            if not done[to]:
                dfs(to, 1^col)
    if not ok:
        print(-1)
        exit(0)

nodes = list(range(n))
nodes.sort(key=lambda x:d[x])
        
for i in nodes:
    if not done[i]:
        dfs(i)


print("".join(list(map(lambda x:"BW"[x], color))))
for c in cost: print(c)
      