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