from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

# In[]:
# N = M = 5
# DD = [3,4,3,5,7]
# uvs = [(1,2),(1,3),(3,2),(4,2),(4,5)]

# In[]:
N,M = inpl()
DD = inpl()
lines = [[] for _ in range(N)]


# In[]:
minD = min(DD)
Start = None
lines = [[] for _ in range(N)]
for i in range(M):
    u,v = inpl()
    u -= 1; v -= 1
    lines[u].append((v,i))
    lines[v].append((u,i))
    if DD[u] == DD[v] == minD:
        Start = (u,v,i)


if Start is None:
    print(-1)
else:
    ans = [10**9] * M
    Su, Sv, Si = Start
    S = "W"*Su + "B" + "W"*(N-Su-1)
    ans[Si] = DD[Su]


    dd = sorted([(d,i) for i,d in enumerate(DD)])
    # print(dd)

    memo = [-1]*N
    memo[Su] = 0
    memo[Sv] = minD

    for d, s in dd:
        if s == Su or s == Sv:
            continue

        # print(d,s, memo)
        for t, Li in lines[s]:
            if memo[t] != -1:
                ans[Li] = d - memo[t]
                memo[s] = d
                break
        else:
            print(-1)
            sys.exit()


    print(S)
    print("\n".join(map(str,ans)))
