I=input
N,M=map(int,I().split())
X,G,d,C=list(map(int,I().split())),[set()for _ in range(N)],[0]*M,[0]*N
for i in range(M):
    u,v=sorted(map(int,I().split()),key=lambda x:[X[x-1],-x])
    G[v-1].add(u-1)
    d[i]=str(X[v-1])
for u in sorted(range(N),key=lambda i:X[i]):
    if C[u]:continue
    if not G[u]:break
    C[u],S=-1 if sum(C[c]+1 for c in G[u])else 1,[u]
    while S:
        q = S.pop()
        for c in G[q]:
            if C[c]:continue
            S+=[c]
            C[c]=-C[q]
print("".join(" BW"[i] for i in C)+"\n"+"\n".join(d)if C[u]else -1)