#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;
int D[100000];
pair<int, int> P[100000];
int U[100000], V[100000];
vector<pair<int,int>> e[100000];

string BW = "";
int ans[200000];

signed main(){
	cin >> N >> M;
	rep(i, N){
		cin >> D[i];
		P[i].first = D[i];
		P[i].second = i;
		BW += "?";
	}
	sort(P, P+N);
	rep(i, M){
		cin >> U[i] >> V[i];
		U[i]--; V[i]--;
		e[U[i]].pb({ V[i],i });
		e[V[i]].pb({ U[i],i });
		ans[i] = 1'000'000'000;
	}


	rep(i, N){
		int j = P[i].second;
		bool flg = false;
		rep(k, e[j].size()){
			if(BW[e[j][k].first] != '?'){
				flg = true;
				ans[e[j][k].second] = D[j];
				BW[j] = (BW[e[j][k].first] == 'B' ? 'W': 'B');
				break;
			}
			if(D[e[j][k].first] == D[j]){
				flg = true;
				ans[e[j][k].second] = D[j];
				BW[e[j][k].first] = 'B';
				BW[j] = 'W';
				break;
			}
		}
		if(!flg){
			exit(1);
			cout << -1 << endl;
			return 0;
		}
	}

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