local n, m = io.read("*n", "*n")
local d = {}
local d_short_idx = {}
local edge = {}
local color = {}
local inf = 1000000007 - 7
for i = 1, n do
  d[i] = io.read("*n")
  edge[i] = {}
  color[i] = 0
  d_short_idx[i] = i
end
table.sort(d_short_idx, function(a, b) return d[a] < d[b] end)
local edgeinfo = {}
for i = 1, m do
  local a, b = io.read("*n", "*n")
  edgeinfo[i] = {a, b, 0}
  table.insert(edge[a], i)
  table.insert(edge[b], i)
end

for id = 1, n do
  local src = d_short_idx[id]
  local asked_edge_color = false
  local samelevel_edge_found = false
  for i = 1, #edge[src] do
    local edge_idx = edge[src][i]
    local e1, e2 = edgeinfo[edge_idx][1], edgeinfo[edge_idx][2]
    local dst = src == e1 and e2 or e1
    if 0 < color[dst] then
      if not asked_edge_color or asked_edge_color < 100 then
        asked_edge_color = color[dst]
      end
    end
    if d[dst] == d[src] then
      samelevel_edge_found = true
    end
  end
  if asked_edge_color then
    if asked_edge_color == 100 then
      color[src] = 2
    else
      color[src] = 3 - asked_edge_color
    end
    for i = 1, #edge[src] do
      local edge_idx = edge[src][i]
      local e1, e2 = edgeinfo[edge_idx][1], edgeinfo[edge_idx][2]
      local dst = src == e1 and e2 or e1
      if color[dst] == color[src] then
        edgeinfo[edge_idx][3] = inf
      else
        edgeinfo[edge_idx][3] = d[src]
      end
    end
  elseif samelevel_edge_found then
    color[src] = 100
  else
    print(-1) os.exit()
  end
end
for i = 1, n do
  if color[i] == 100 then color[i] = 1 end
  assert(0 < color[i] and color[i] <= 2)
  io.write(color[i] == 1 and "W" or "B")
end
io.write("\n")
for i = 1, m do
  print(edgeinfo[i][3])
end
