/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
int n,m;
int d[100005];
vector<pair<int,int> >g[100005];
vector<int>rg[100005];
bool root[100005];
int dat[100005];
int a[100005],b[100005],c[100005];
vector<pair<int,int> >tree[100005];
bool vis[100005];
int rt,p[100005],par[100005];
void dfs(int x){
	vis[x]=1;p[x]=rt;par[x]=rt;
	for(auto p:g[x]){
		if(!vis[p.first]){
			tree[x].push_back(p);
			c[p.second]=d[p.first]-d[x];
			dfs(p.first);
		}else{
			c[p.second]=1e9;
		}
	}
}
int used[100005],color[100005];
int find(int x){return x==par[x]?x:par[x]=find(par[x]);}
bool same(int x,int y){return find(x)==find(y);}
void merge(int x,int y){par[find(x)]=find(y);}
void go(int x){
	used[x]=1;
	for(auto to:rg[x]){
		color[to]=color[x]^1;go(to);
	}
}
void pushdown(int x){
	for(auto p:tree[x]){
		color[p.first]=color[x];pushdown(p.first);
	}
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)par[i]=i;
	for(int i=1;i<=n;i++)cin>>d[i];
	for(int i=1;i<=n;i++)root[i]=1;
	for(int i=1;i<=m;i++){
		int x,y;cin>>x>>y;
		a[i]=x;b[i]=y;
		if(d[x]<d[y]){
			g[x].push_back(make_pair(y,i));
			root[y]=0;
		}
		if(d[y]<d[x]){
			g[y].push_back(make_pair(x,i));
			root[x]=0;
		}
	}
	for(int i=1;i<=n;i++)if(root[i]){
		rt=i;dfs(i);
	}
	for(int i=1;i<=m;i++){
		if(d[a[i]]==d[b[i]]){
			if((root[a[i]]||root[b[i]])&&!same(a[i],b[i])){
//				cerr<<p[a[i]]<<" "<<p[b[i]]<<endl;
				c[i]=d[a[i]];rg[p[a[i]]].push_back(p[b[i]]);merge(a[i],b[i]);
			}else{
				c[i]=1e9;
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(!used[i])if(root[i]){
			color[i]=1;go(i);
		}
	}
	for(int i=1;i<=n;i++){
		if(root[i])pushdown(i);
	}
	if(*max_element(color+1,color+n+1)==*min_element(color+1,color+n+1)){
		puts("-1");
	}else{
		for(int i=1;i<=n;i++)if(color[i])cout<<"B";else cout<<"W";cout<<endl;
		for(int i=1;i<=m;i++)cout<<c[i]<<endl;
	}
	return 0;
}