#include<bits/stdc++.h>
using namespace std;
const int N=1e5+2;
const int M=2e5+2;
int ar[N],val[M],lis[N],color[N];
vector<pair<int,int> > adj[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,m,v;
	cin>>n>>m;
	for(i=1;i<=n;i++){
		cin>>ar[i];
		lis[i]=i;
		color[i]=-1;
	}
	for(i=1;i<=m;i++){
		cin>>j>>k;
		adj[j].push_back({k,i});
		adj[k].push_back({j,i});
	}
	sort(lis+1,lis+1+n,[&](int x,int y){
		return ar[x]<ar[y];	
	});
	for(i=1;i<=n;i++){
		v=lis[i];
		if(color[v]!=-1){
			continue;
		}
		bool cac=true;
		for(auto x:adj[v]){
			j=x.first; k=x.second;
			if(ar[v]>=ar[j]){
				if(color[j]!=-1){
					color[v]=1-color[j];
				}
				else{
					color[v]=0;
					color[j]=1;
				}
				val[k]=ar[v];
				cac=false;
				break;
			}
		}
		if(cac){
			cout<<-1;
			return 0;
		}
	}
	for(i=1;i<=n;i++){
		if(!color[i]){
			cout<<'B';
		}
		else{
			cout<<'W';
		}
	}
	cout<<'\n';
	for(i=1;i<=m;i++){
		if(!val[i]){
			val[i]=1000000000;
		}
		cout<<val[i]<<'\n';
	}
}