import sys
input = sys.stdin.readline
N, M = map(int, input().split())
xs = 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:[xs[x-1],-x])
    G[v-1].add((u-1,i))
xs,d,cc = sorted([(x,i) for i, x in enumerate(xs)]),[0]*M,[-1]*N
for x, u in xs:
    if cc[u]+1:continue
    if not G[u]:break
    cc[u] = 1
    for c, _ in G[u]:
        if cc[c]+1:
            cc[u] = 1-cc[c]
    S = [u]
    while S:
        q = S.pop()
        for c, i in G[q]:
            d[i] = str(x)
            if cc[c]+1:continue
            S.append(c)
            cc[c] = 1-cc[q]
print("".join("BW"[i] for i in cc)+"\n"+"\n".join(d) if cc[u]+1 else -1)