#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
char col[100005];
int D[100005];
vector<int> F[100005], E[100005];
bool used[100005];
void go(int x, int w = 0) {
	if (col[x]) return;
	col[x] = "BW"[w];
	used[x] = true;
	for (int y : F[x]) {
		go(y, 1 - w);
	}
}
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i) scanf("%d", &D[i]);
	vector<pair<int, int>> edges;
	for (int i = 0; i < m; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		--u;
		--v;
		edges.emplace_back(u, v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	vector<int> nex(n, -1);
	for (int i = 0; i < n; ++i) {
		for (int j : E[i]) {
			if (D[j] <= D[i]) {
				nex[i] = j;
				F[j].push_back(i);
				break;
			}
		}
		if (nex[i] == -1) {
			printf("-1\n");
			return 0;
		}
	}
	for (int i = 0; i < n; ++i) {
		if (used[i]) continue;
		int x = i;
		while (!used[x]) {
			used[x] = true;
			x = nex[x];
		}
		go(x);
	}
	col[n] = '\0';
	printf("%s\n", col);
	for (auto& e : edges) {
		int u, v;
		tie(u, v) = e;
		printf("%d\n", max(D[u], D[v]));
	}
}
