n, m = read_line.split.map(&.to_i)
d = read_line.split.map(&.to_i)
g = Array.new(n) { [] of Int32 }
ei = Array.new(n) { [] of Int32 }
m.times do |i|
  u, v = read_line.split.map(&.to_i)
  g[u - 1] << v - 1
  g[v - 1] << u - 1
  ei[u - 1] << i
  ei[v - 1] << i
end
color = Array.new(n, 0)
edge_w = Array.new(m, 0)
(0...n).to_a.sort_by { |i| d[i] }.each do |i|
  found = false
  g[i].each_with_index do |adj, j|
    next if d[adj] > d[i]
    found = true
    if color[adj] == 0
      color[i] = 1
      color[adj] = -1
    else
      color[i] = -color[adj]
    end
    edge_w[ei[i][j]] = d[i]
    break
  end
  if !found
    puts -1
    exit
  end
end
puts n.times.map { |i| color[i] == 1 ? 'W' : 'B' }.join
edge_w.each do |w|
  puts w == 0 ? 1000000000 : w
end
