#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;
vvp g;
vi a,b,c,vis,res;

void dfs(int v,int t){
	vis[v]=t;
	for(auto p:g[v]){
		int u=p.first,id=p.second;
		if(vis[u]!=t&&a[u]<=a[v]){
			res[id]=a[v];
			if(!vis[u]) dfs(u,t);
			b[v]=b[u]^1;
			break;
		}
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	g=vvp(n);
	a=vis=b=vi(n);
	c=res=vi(m);
	for(auto &i:a) cin>>i;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u].push_back({v,i});
		g[v].push_back({u,i});
	}
	bool B=0;
	for(int i=0;i<n;i++){
		bool flag=1;
		for(auto p:g[i]){
			int v=p.first;
			if(a[v]<=a[i]) flag=0;
		}
		B|=flag;
	}
	if(B){
		cout<<-1<<endl;
		return 0;
	}
	int id=1;
	for(int i=0;i<n;i++) if(!vis[i]) dfs(i,id++);
	for(int i=0;i<n;i++) cout<<(b[i]?'B':'W');
	cout<<endl;
	for(int i=0;i<m;i++){
		if(!res[i]) cout<<1000000000<<endl;
		else cout<<res[i]<<endl;
	}
}