#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N,M; cin >> N >> M;
	V<int> D(N); rep(i,N) cin >> D[i];
	VV<int> G(N);
	using P = pair<int,int>;
	map<P,int> mp;
	rep(i,M){
		int x,y; cin >> x >> y; x--,y--;
		G[x].pb(y);G[y].pb(x);
		mp[P(x,y)] = i;
		mp[P(y,x)] = i;
	}
	V<int> vs(N); rep(i,N) vs[i] = i;
	sort(all(vs),[&](int l,int r){return D[l]<D[r];});
	V<int> ans(M,1e9);
	string col(N,'?');
	rep(i,N){
		int v = vs[i];
		if(col[v] != '?') continue;
		for(int u: G[v]) if(col[u] != '?' || D[v] == D[u]){
			int eid = mp[P(v,u)];
			ans[eid] = D[v];
			if(col[u] == '?'){
				col[u] = 'B';
			}
			col[v] = col[u] ^ 'B' ^ 'W';
			break;
		}
		if(col[v] == '?'){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << col << endl;
	rep(i,M) cout << ans[i] << endl;
}
