#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
const ll MOD = 1000000007;

vector<pair<int,int>> G[200010];
char BW[200010];
map<pair<int,int>, int> edge;
int ans[200010];

int main() {
	int N, M, U, V, dis;
	cin >> N >> M;
	vector<int> D(N);
	vector<pair<int, int>> Ds(N);
	for (int i = 0;i < N;i++) {
		cin >> D[i];
		Ds[i] = { D[i],i };
	}
	sort(all(Ds));
	vector<pair<int, int>> Vs(M);

	for (int i = 0;i < M;i++) {
		cin >> U >> V;
		U--;V--;
		G[U].push_back(make_pair(D[V], V));
		G[V].push_back(make_pair(D[U], U));
		edge.insert({ {U,V},1000000000 });
		edge.insert({ {V,U},1000000000 });
		Vs[i] = { U,V };
	}

	for (int i = 0;i < N;i++) {
		sort(all(G[i]));
		BW[i] = 49;
	}

	
	int gs, fir, sec, s, t;
	for (int x = 0, i;x < N;x++) {
		i = Ds[x].second;
		dis = Ds[x].first;

		fir = G[i][0].first;
		sec = G[i][0].second;
		//for (int k = 0;k < N;k++)cout << BW[k];cout << endl;
		if (fir < dis) {
			if (BW[i] == 49) {
				edge[{i, sec}] = dis - fir;
				edge[{sec, i}] = dis - fir;
				BW[i] = BW[sec];
			}
		}
		else if (fir == dis) {
			edge[{i, sec}] = dis;
			edge[{sec, i}] = dis;
			if (BW[i] == 49) {
				if (BW[sec] == 'B')BW[i] = 'W';
				else BW[i] = 'B', BW[sec] = 'W';
			}
			else if (BW[sec] == 49) {
				if (BW[i] == 'B')BW[sec] = 'W';
				else BW[sec] = 'B';
			}
		}
		else {
			cout << -1 << endl;
			return 0;
		}
	}
	for (int i = 0;i < N;i++) {
		cout << BW[i];
	}
	cout << endl;

	for (int i = 0;i < M;i++) {
		cout << edge[Vs[i]] << endl;
	}
}