#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 200010
vector<ll> g[N];
ll n,m,a[N],b[N],c[N],d[N],len[N];
vector<ll> f[N];
bool us[N];
ll col[N];
void dfs(ll x,bool co){
    if(~col[x])return;
    col[x]=co;
    for(auto y:f[x]){
	dfs(y,co^1);
    }
}
int main(){
    cin>>n>>m;
    rep(i,n)cin>>d[i];
    rep(i,m){
	cin>>a[i]>>b[i];
	a[i]--,b[i]--;
	len[i]=max(d[a[i]],d[b[i]]);
	g[a[i]].push_back(i);
	g[b[i]].push_back(i);
    }
    bool ok=1;
    rep(i,n){
	ll mi=1e17,eid=0;
	for(auto e:g[i]){
	    if(mi>len[e]){
		eid=e;
		mi=len[e];
	    }
	}
	us[eid]=1;
	if(d[i]!=mi)ok=0;
    }
    if(ok==0){
	cout<<-1<<endl;
	return 0;
    }
    rep(i,m)if(us[i]){
	f[a[i]].push_back(b[i]);
	f[b[i]].push_back(a[i]);
    }
    rep(i,n)col[i]=-1;
    rep(i,n)dfs(i,0);
    rep(i,n)cout<<(col[i]?"B":"W"); cout<<endl;
    rep(i,m)cout<<len[i]<<endl;
}


