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