use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

const MAX: usize = 1_000_000_000;
fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, m: usize, d: [usize; n]);
    let mut g = vec![vec![]; n];
    for i in 0..m {
        parse!(it, u: usize, v: usize);
        g[u - 1].push((v - 1, i));
        g[v - 1].push((u - 1, i));
    }
    let mut retv: Vec<Option<bool>> = vec![None; n];
    let mut rete = vec![MAX; m];
    let mut e = d
        .iter()
        .enumerate()
        .map(|(i, x)| (*x, i))
        .collect::<Vec<_>>();
    e.sort();
    'outer: for &(di, i) in e.iter() {
        for &(j, ei) in g[i].iter() {
            if d[j] > di {
                continue;
            }
            if let Some(b) = retv[j] {
                retv[i] = Some(!b);
                rete[ei] = di;
            } else {
                retv[i] = Some(true);
                retv[j] = Some(false);
                rete[ei] = di;
            }
            continue 'outer;
        }
        println!("{}", -1);
        return;
    }
    println!(
        "{}",
        retv.into_iter()
            .map(|x| if x.unwrap() { "B" } else { "W" })
            .collect::<Vec<_>>()
            .join("")
    );
    for i in 0..m {
        println!("{}", rete[i]);
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}
