#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
vector<int> g[maxn];
int d[maxn],vis[maxn];
int ord[maxn];
int ans[maxn],u[maxn],v[maxn];
queue<int> q;
map<pii,int> rev;
void shit(){
	puts("-1");
	exit(0);
}
bool cmp(int i,int j){
	return d[i]<d[j];
}
void cdd(int x,int y,int v){
	if(x>y)swap(x,y);
	int k = rev[mp(x,y)];
	ans[k] = v;
}
int main()
{
	int n,m;cin>>n>>m;
	for(int i=1;i<=n;i++)scanf("%d",&d[i]),ord[i] = i;
	sort(ord+1,ord+1+n,cmp);
//	if(d[ord[2]]!=d[ord[1]])shit();
	int mini = d[ord[1]];
	memset(vis,-1,sizeof(vis));
	for(int i=1;i<=m;i++){
		scanf("%d%d",&u[i],&v[i]);
		if(u[i]>v[i])swap(u[i],v[i]);
		rev[mp(u[i],v[i])] = i;
		g[u[i]].pb(v[i]);
		g[v[i]].pb(u[i]);
		ans[i] = 1e9;
	}
	for(int i=1;i<=n;i++){
		int x = ord[i];
		if(vis[x]!=-1)continue;
		for(int y:g[x]){
			if(vis[y]!=-1){
				vis[x] = vis[y]^1;
				cdd(x,y,d[x]);
				break;
			}
			if(d[y]==d[x]){
				vis[x] = 0;
				vis[y] = 1;
				cdd(x,y,d[x]);
				break;
			}
		}
	}
	for(int i=1;i<=n;i++)if(vis[i]==-1)shit();
	for(int i=1;i<=n;i++){
		if(vis[i])putchar('B');
		else putchar('W');
	}
	puts("");
	for(int i=1;i<=m;i++)printf("%d\n",ans[i]);
	return 0;
}
