package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  "sort"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

type Node [][]int
func (N Node) Len() int { return len(N) }
func (N Node) Less(i, j int) bool { return N[i][0] < N[j][0] }
func (N Node) Swap(i, j int) { N[i], N[j] = N[j], N[i] }

func Solve() {
  NM := NextIntVec()
  N, M := NM[0], NM[1]
  D := NextIntVec()
  G := make([][][]int, N)
  for i := range G {
    G[i] = make([][]int, 0)
  }
  E := make([]int, M)
  for i := range E {
    UV := NextIntVec()
    u, v := UV[0] - 1, UV[1] - 1
    G[u] = append(G[u], []int{v, i})
    G[v] = append(G[v], []int{u, i})
  }
  V := make([]string, N)
  for i := range V {
    V[i] = "B"
  }
  for u, g := range G {
    sort.Sort(Node(g))
    adj := u
    for _, v := range g {
      if D[u] < D[v[0]] { continue }
      adj = v[0]
      E[v[1]] = D[u]
      if V[v[0]] == "B" {
        V[u] = "W"
      } else {
        V[u] = "B"
      }
      break
    }
    if adj == u {
      Write(-1)
      return
    }
  }
  Write(strings.Join(V, ""))
  for i, e := range E {
    if e < 1 { E[i] = 1000000000 }
    Write(E[i])
  }
  return
}

func main() {
  Solve()
  Output()
}