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 = inpl()
DD = inpl()
lines = [[] for _ in range(N)]


# In[]:
Start = None
lines = [[] for _ in range(N)]
memo = [10**10]*N
ans = [10**9] * M
SS = [False]*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] and memo[u]==10**10 and memo[v]==10**10:
        SS[u] = True
        memo[u] = 0
        memo[v] = DD[u]
        ans[i] = DD[u]


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

for d, s in dd:
    if memo[s] != 10**10:
        continue
    # print(d,s, memo)
    flag = True
    for t, Li in lines[s]:
        tmp = d-memo[t]
        if tmp > 0:
            ans[Li] = d - memo[t]
            memo[s] = d
            flag = False
        elif tmp == 0:
            ans[Li] = DD[s]
            memo[s] = 0
            SS[s] = True
            flag = False

    if flag:
        print(-1)
        sys.exit()


print("".join(["B" if S else "W" for S in SS]))
print("\n".join(map(str,ans)))
