#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

bool chk[100009], bl[100009];
vector<pii> G[100009];
int D[100009], w[200009];

int main() {
	int N, M; scanf("%d%d",&N,&M);
	for(int i=1; i<=N; i++) scanf("%d", &D[i]);
	for(int i=0; i<M; i++) {
		int u, v; scanf("%d%d",&u,&v);
		G[u].push_back({v, i});
		G[v].push_back({u, i});
		w[i] = 1e9;
	}
	vector<int> S;
	for(int i=1; i<=N; i++) S.push_back(i);
	sort(S.begin(), S.end(), [&](int P, int Q) { return D[P] < D[Q]; });
	for(auto& it: S) {
		if(chk[it]) continue;
		chk[it] = 1;
		int nei = -1, id = -1;
		for(auto& jt: G[it]) if(chk[jt.first]) tie(nei, id) = jt;
		if(nei != -1) {
			w[id] = D[it];
			bl[it] = bl[nei] ^ 1;
		}
		else {
			for(auto& jt: G[it]) if(D[jt.first] == D[it]) tie(nei, id) = jt;
			if(nei != -1) {
				chk[nei] = 1;
				w[id] = D[it];
				bl[it] = 1;
			}
			else return !printf("-1");
		}
	}
	for(int i=1; i<=N; i++) {
		if(bl[i]) printf("B");
		else printf("W");
	}
	for(int i=0; i<M; i++) printf("\n%d", w[i]);
	return 0;
}