# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n)) #親ノード
        self.size = [1]*n #グループの要素数
 
    def root(self, x): #root(x): xの根ノードを返す．
        while self.parent[x] != x:
            self.parent[x] = self.parent[self.parent[x]]
            x = self.parent[x]
        return x 
 
    def merge(self, x, y): #merge(x,y): xのいる組とyのいる組をまとめる
        x, y = self.root(x), self.root(y)
        if x == y: return False
        if self.size[x] < self.size[y]: x,y=y,x #xの要素数が大きいように
        self.size[x] += self.size[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True
 
    def issame(self, x, y): #same(x,y): xとyが同じ組ならTrue
        return self.root(x) == self.root(y)
        
    def getsize(self,x): #size(x): xのいるグループの要素数を返す
        return self.size[self.root(x)]


#n = int(input)
#h,w = [int(i) for i in readline().split()]
#n,k,s = [int(i) for i in read().split()]

#n = int(input())
#a = [int(i)-1 for i in readline().split()]
n,m = [int(i) for i in readline().split()]
d = [int(i) for i in readline().split()]

g = [[] for _ in range(n)]
a = map(int,read().split())

INF = 10**9

#edges = []
for i,(u,v) in enumerate(zip(a,a)):
    u -= 1; v -= 1
    g[u].append((v,i))
    g[v].append((u,i))
    #edges.append((u,v))

ans = [INF]*m

dd = [(c,i) for i,c in enumerate(d)]
dd.sort()

UF = UnionFind(2*n)

for c,idx in dd:
    for (v,i) in g[idx]:
        if d[v] <= c:
            UF.merge(v,idx+n)
            UF.merge(v+n,idx)
            ans[i] = c
            break
    else:
        print(-1)
        exit()
s = []
for i in range(2*n):
    if UF.issame(0,i):
        if i < n:
            s.append("W")
        else:
            s.append("B")

print("".join(s))
    

print(*ans,sep="\n")

    
    
    







