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

const int maxn = 1e5, maxm = 4e5, inf = 1e9;
int n, m, d[maxn + 3], tot, ter[maxm + 3], nxt[maxm + 3], wei[maxm + 3], lnk[maxn + 3], to[maxn + 3], id[maxn + 3];
vector<int> S[maxn + 3];
bool vis[maxn + 3];
char s[maxn + 3];

void add(int u, int v) {
	ter[++tot] = v, wei[tot] = inf, nxt[tot] = lnk[u], lnk[u] = tot;
}

void dfs(int u) {
	vis[u] = true;
	for (int i = 0, e, v; i < S[u].size(); i++) {
		e = S[u][i], v = ter[e];
		if (!vis[v]) {
			wei[e] = wei[e & 1 ? e + 1 : e - 1] = d[v];
			s[v] = s[u] ^ 'W' ^ 'B', dfs(v);
		}
	}
}

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
	for (int i = 1, u, v; i <= m; i++) {
		scanf("%d %d", &u, &v), add(u, v), add(v, u);
	}
	bool flag = true;
	for (int i = 1; i <= n; i++) {
		pair<int, int> p = make_pair(inf, inf);
		int e = 0;
		for (int j = lnk[i], v; j; j = nxt[j]) {
			v = ter[j];
			if (make_pair(d[v], v) < p) {
				p = make_pair(d[v], v), e = j;
			}
		}
		if (p.first > d[i]) { flag = false; break; }
		to[i] = p.second, id[i] = e, S[to[i]].push_back(e & 1 ? e + 1 : e - 1);
	}
	if (!flag) puts("-1"), exit(0);
	for (int i = 1; i <= n; i++) if (!vis[i] && to[to[i]] == i) s[i] = 'W', dfs(i);
	puts(s + 1);
	for (int i = 1; i <= m; i++) printf("%d\n", wei[i * 2]);
	return 0;
}