#include <bits/stdc++.h>

#define I inline
#define fi first
#define se second
#define R register
#define LL long long
#define mp make_pair
#define reg register int
#define pii pair<int,int>
#define fo(i, a, b) for(reg i = a; i <= b; i++)
#define fd(i, a, b) for(reg i = a; i >= b; i--)
#define cr const reg&
using namespace std;
const int N = 1e5 + 1, inf = 1e9;

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I int read() {
	reg x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(LL x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(LL x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(LL x) {put(x), putchar(' ');}
I void pr2(LL x) {put(x), puts("");}

struct edge {
	int x, y, next;
} e[N * 4]; int len, last[N];
int d[N], c[N], fa[N], p[N * 2];

I void ins(cr x, cr y) {e[++len] = edge{x, y, last[x]}, last[x] = len;}

I int dfs(cr x) {
	if(!last[x]) {p[fa[x] / 2] = d[x]; return d[x];}
	reg hh = inf;
	for(reg k = last[x]; k; k = e[k].next) {
		reg y = e[k].y;
		if(!c[y]) {
			c[y] = 3 - c[x];
			fa[y] = k;
			hh = _min(hh, dfs(y));
		}
	} if(x == 1) {
		if(hh != d[x]) {puts("-1"); exit(0);}
	} else {
		if(hh < d[x]) {puts("-1"); exit(0);}
		else if(hh == d[x]) p[fa[x] / 2] = d[e[fa[x]].x];
		else p[fa[x] / 2] = d[x];
		return p[fa[x] / 2];
	}
}

int main() {
	reg n = read(), m = read();
	fo(i, 1, n) d[i] = read();
	len = 1;
	fo(i, 1, m) {
		reg x = read(), y = read();
		ins(x, y), ins(y, x);
	} c[1] = 1, dfs(1);
	fo(i, 1, n) putchar(c[i] == 1 ? 'B' : 'W'); puts("");
	fo(i, 1, m) pr2(!p[i] ? inf : p[i]);
	return 0;
}

