#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);--i)
#define P pair<int,int>
#define pb push_back
#define lb(x) (x&(-x))
#define ALL(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long LL;
const int M = 220000;
const int inf = 1e9;
int c[M]={0};
P p[M];
vector<P> g[M];
int n,m,k;
int dd[M];
char s[M];
bool ok(int i){
	return s[i]=='W'||s[i]=='B';
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	int u,v;
	fo(i,1,n){
		cin>>p[i].first;
		dd[i]=p[i].first;
		p[i].second=i;
	}
	sort(p+1,p+1+n);
	fo(i,1,m){
		cin>>u>>v;
		g[u].push_back({v,i});
		g[v].push_back({u,i});
	}
	int flag=1;
	fo(i,1,n){
		int id=p[i].second;
		if(ok(id)) continue;
		int d=p[i].first;
		bool done=0;
		for(P to:g[id]){
			if(ok(to.first)){
				c[to.second]=d;
				s[id]=(s[to.first]=='W'?'B':'W');
				done=1;
				break;
			}
		}
		if(!done){
			for(P to:g[id]){
				if(dd[to.first]==d){
					done=1;
					s[id]='W';
					s[to.first]='B';
					c[to.second]=d;
				}
			}
		}
		if(!done){
			flag=0;
			break;
		}
	}
	if(flag){
		s[n+1]='\0';
		cout<<s+1<<endl;
		fo(i,1,m){
			cout<<(c[i]?c[i]:inf)<<endl;
		}
	}
	else cout<<-1<<endl;
	return 0;
}
