#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N, M, D[100000], U[100000], V[100000];
vector<int> e[100000];
unordered_set<int> s[100000];
string BW = "";
int numBlack;
vector<int> white;
int ans[200000];

void changeBlack(int i){
	vector<int> _white;
	queue<int> que;
	rep(j, white.size()){
		if(white[j] == i) continue;
		if(s[i].count(white[j]) == 0){
			que.push(white[j]);
		}
		else{
			_white.pb(white[j]);
		}
	}
	white = _white;
	while(!que.empty()){
		int j = que.front();
		que.pop();
		if(BW[j] == 'B') continue;
		changeBlack(j);
	}
}

signed main(){
	cin >> N >> M;
	rep(i, N){
		cin >> D[i];
		BW += "B";
	}
	rep(i, M){
		cin >> U[i] >> V[i];
		U[i]--; V[i]--;
		e[U[i]].pb(V[i]);
		s[U[i]].insert(V[i]);
		e[V[i]].pb(U[i]);
		s[V[i]].insert(U[i]);
	}

	int idx = 0;
	rep(i, N){
		if(e[i].size() < e[idx].size()) idx = i;
	}
	rep(i, e[idx].size()){
		BW[e[idx][i]] = '?';
	}
	numBlack = N - e[idx].size();

	rep(i, e[idx].size()){
		int j = e[idx][i];
		int tmp = 0;
		rep(k, e[j].size()){
			if(BW[e[j][k]] == 'B') tmp++;
		}
		if(tmp < numBlack){
			changeBlack(j);
		}
		else{
			white.pb(j);
		}
	}

	if(white.size() == 0){
		cout << -1 << endl;
		return 0;
	}

	rep(i, N) if(BW[i] == '?') BW[i] = 'W';
	
	rep(i, M){
		if(BW[U[i]] == BW[V[i]]) ans[i] = 1'000'000'000;
		else{
			if(D[U[i]] != D[V[i]]){
				cout << -1 << endl;
				return 0;
			}
			ans[i] = D[U[i]];
		}
	}

	cout << BW << endl;
	rep(i, M) cout << ans[i] << endl;
}