import sys
input = sys.stdin.readline

N,M=map(int,input().split())
D=list(map(int,input().split()))
EDGE=[tuple(sorted(map(int,input().split()))) for i in range(M)]
DICE=dict()

for i in range(M):
    DICE[EDGE[i]]=i
    
E=[[] for i in range(N+1)]

for x,y in EDGE:
    E[x].append(y)
    E[y].append(x)

P=[(x,ind+1) for ind,x in enumerate(D)]
P.sort()
D=[0]+D

DECIDED=[""]*(N+1)
DIS=[-1]*M

for x,po in P:
    flag=0
     
    for to in E[po]:
        if DECIDED[to]!="":
            flag=1
            break

    if flag==0:
        for to in E[po]:
            if D[to]==x:
                DIS[DICE[tuple(sorted([po,to]))]]=x
                DECIDED[po]="B"
                DECIDED[to]="W"
                break
        else:
            print(-1)
            sys.exit()

    else:            
        for to in E[po]:
            if DECIDED[to]!="" and DECIDED[po]=="":
                if DECIDED[to]=="B":
                    DECIDED[po]="W"
                else:
                    DECIDED[po]="B"
                    
                DIS[DICE[tuple(sorted([po,to]))]]=x
                break

            elif DECIDED[to]!="" and DECIDED[po]==DECIDED[to]:
                if x<=D[to]:
                    continue
                    
                DIS[DICE[tuple(sorted([po,to]))]]=x-D[to]
                break

            elif DECIDED[to]!="" and DECIDED[po]!=DECIDED[to]:
                if x<=D[to]:
                    continue
                    
                DIS[DICE[tuple(sorted([po,to]))]]=x
                break
        
print("".join(DECIDED[1:]))
for d in DIS:
    if d==-1:
        print(10**9)
    else:
        print(d)
        

    
            
    
    

