#include <bits/stdc++.h>
using namespace std;

const int N = 100005, M = 200005, inf = 1000000000;

template <class T>
void read (T &x) {
	int sgn = 1;
	char ch;
	x = 0;
	for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
	if (ch == '-') ch = getchar(), sgn = -1;
	for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}

template <class T>
void write (T x) {
	if (x < 0) putchar('-'), write(-x);
	else if (x < 10) putchar(x + '0');
	else write(x / 10), putchar(x % 10 + '0');
}

int n, m, fa[N], val[N], d[N], e[M];
bool vis[N], flag = true;

int findroot (int u) {
	if (fa[u] == u) return u;
	int r = findroot(fa[u]);
	assert(fa[fa[u]] == r);
	val[u] ^= val[fa[u]], fa[u] = r;
	return r;
}
bool merge (int u, int v) {
	int ru = findroot(u), rv = findroot(v);
	if (ru == rv) return false;
	fa[ru] = rv, val[ru] = val[u] ^ val[v] ^ 1;
	return true;
}
int main () {
	read(n), read(m);
	for (int i = 1; i <= n; i++) {
		fa[i] = i, val[i] = 0;
		vis[i] = false, read(d[i]);
	}
	for (int i = 1; i <= m; i++) {
		int u, v;
		read(u), read(v), e[i] = inf;
		bool need_add = false;
		if (d[v] <= d[u] && !vis[u]) need_add = true;
		if (d[u] <= d[v] && !vis[v]) need_add = true;
		if (need_add) {
			merge(u, v), e[i] = max(d[u], d[v]);
			if (d[v] <= d[u]) vis[u] = true;
			if (d[u] <= d[v]) vis[v] = true;
		}
	}

	for (int i = 1; i <= n; i++) flag &= vis[i];
	if (flag) {
		for (int i = 1; i <= n; i++) findroot(i), putchar(val[i] ? 'B' : 'W');
		putchar('\n');
		for (int i = 1; i <= m; i++) write(e[i]), putchar('\n');
	}
	else puts("-1");
	return 0;
}