from collections import defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    def impossible():
        for u in range(n):
            du = dd[u]
            for v in to[u]:
                if dd[v] <= du: break
            else:
                return True
        return False

    def dfs(u=0,pu=-1,c=0):
        color[u]="B" if c else "W"
        for v in to2[u]:
            if v==pu:continue
            dfs(v,u,1-c)

    inf = 10 ** 9
    n, m = MI()
    dd = LI()
    to = defaultdict(list)
    uvtoi = {}
    for i in range(m):
        u, v = MI1()
        uvtoi[u, v] = uvtoi[v, u] = i
        to[u].append(v)
        to[v].append(u)
    if impossible():
        print(-1)
        exit()
    cost = [inf] * m
    to2 = defaultdict(set)
    for u in range(n):
        mn = (inf, inf, inf)
        for v in to[u]:
            t = (dd[v], uvtoi[u, v], v)
            if t < mn: mn = t
        v = mn[2]
        cost[mn[1]] = dd[u]
        to2[u].add(v)
        to2[v].add(u)
    color=[""]*n
    dfs()
    print("".join(color))
    print(*cost,sep="\n")

main()
