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

#define fi first
#define se second

#define N 100005

int n, m, D[N], id[N], d[N*2];

int col[N];

using pii = pair <int, int>;

vector <pii> v[N];

bool vis[N];

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i ++) scanf("%d", &D[i]), id[i] = i;
	for (int i = 1, x, y; i <= m; i ++) {
		scanf("%d %d", &x, &y);
		v[x].emplace_back(y, i);
		v[y].emplace_back(x, i);
	}
	sort(id+1, id+n+1, [](int x, int y) {return D[x] < D[y];});
	for (int i = 1; i <= n; i ++) {
		int u = id[i];
		if (vis[u]) continue;
		bool flag = 0;
		for (auto x : v[u]) if (vis[x.fi]) {
			d[x.se] = D[u];
			col[u] = col[x.fi] ^ 1;
			flag = 1;
			vis[u] = 1;
			break;
		}
		if (flag) continue;
		for (auto x : v[u]) if (D[x.fi] == D[u]) {
			d[x.se] = D[u];
			vis[u] = vis[x.fi] = 1;
			col[u] = 1, col[x.fi] = 0;
			flag = 1;
			break;
		}
		if (!flag) {
			puts("-1");
			return 0;
		}
	}
	for (int i = 1; i <= n; i ++) printf("%c", "BW"[col[i]]);
	puts("");
	for (int i = 1; i <= m; i ++) {
		if (d[i] == 0) d[i] = 1e9;
		printf("%d\n", d[i]);
	}
	return 0;
}
