use std::cmp::max;
use std::collections::BTreeMap;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let m: usize = sc.read();
    let d: Vec<u64> = sc.vec(n);
    let mut graph = vec![vec![]; n];
    for i in 0..m {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push((b, i));
        graph[b].push((a, i));
    }

    let mut tree = vec![vec![]; n];
    let mut ans = vec![1e9 as u64; m];
    for i in 0..n {
        let (_, j, e) = graph[i].iter().map(|&(i, e)| (d[i], i, e)).min().unwrap();
        if d[i] < d[j] {
            println!("-1");
            return;
        }
        tree[i].push(j);
        tree[j].push(i);
        ans[e] = d[i];
    }

    let mut c = vec![0; n];
    for i in 0..n {
        if c[i] == 0 {
            continue;
        }
        c[i] = 1;
        color(i, &tree, &mut c);
    }

    for c in c.into_iter() {
        sc.write(if c == 1 { "W" } else { "B" });
    }
    sc.write("\n");
    for ans in ans.into_iter() {
        sc.write(ans);
        sc.write("\n");
    }
}

fn color(v: usize, tree: &Vec<Vec<usize>>, c: &mut Vec<usize>) {
    for &next in tree[v].iter() {
        if c[next] == 0 {
            c[next] = if c[v] == 1 { 2 } else { 1 };
            color(next, tree, c);
        } else {
            assert_ne!(c[v], c[next]);
        }
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
