import sys
from operator import itemgetter


def solve(n, m, ddd, links):
    ddi = list(enumerate(ddd))
    ddi.sort(key=itemgetter(1))
    colors = [-1] * n
    costs = [10 ** 9] * m

    for v, dv in ddi:
        du, li, u = min(links[v])
        if du > dv:
            print(-1)
            return
        if colors[u] == -1:
            if colors[v] == -1:
                colors[v] = 0
                colors[u] = 1
            else:
                colors[u] = colors[v] ^ 1
        else:
            colors[v] = colors[u] ^ 1
        costs[li] = dv
    print(''.join('BW'[c] for c in colors))
    print('\n'.join(map(str, costs)))


n, m = map(int, input().split())
ddd = list(map(int, input().split()))
links = [[] for _ in range(n)]
for li, line in enumerate(sys.stdin):
    u, v = map(int, line.split())
    u -= 1
    v -= 1
    links[u].append((ddd[v], li, v))
    links[v].append((ddd[u], li, u))
solve(n, m, ddd, links)
