#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
const int N = 666666;
vector<int> e[N];int n,m,d[N],id[N],pos[N],col[N],A[N],B[N];bool ok[N];
bool cmp(int x, int y){return d[x]<d[y];}
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
        scanf("%d",&d[i]);
        id[i]=i;
	}
	for(int i=1;i<=m;i++){
		scanf("%d%d",&A[i],&B[i]);
		e[A[i]].push_back(B[i]);
		e[B[i]].push_back(A[i]);
	}
	sort(id+1,id+n+1,cmp);
	for(int i=1;i<=n;i++)pos[id[i]]=i;
	for(int i=1;i<=n;i++){
		int x=0;
		for(int j=0;j<e[id[i]].size();j++)if(pos[e[id[i]][j]]<i)
			x=col[e[id[i]][j]]^1;
		for(int j=0;j<e[id[i]].size();j++)if(pos[e[id[i]][j]]<i&&!ok[e[id[i]][j]])
			x=col[e[id[i]][j]]^1;
		col[id[i]]=x;
		for(int j=0;j<e[id[i]].size();j++)if(pos[e[id[i]][j]]<i&&col[e[id[i]][j]]!=x)
			ok[id[i]]=1,ok[e[id[i]][j]]|=d[e[id[i]][j]]==d[id[i]];
	}
	for(int i=1;i<=n;i++)if(!ok[i]){puts("-1");return 0;}
	for(int i=1;i<=n;i++)printf("%c",col[i]?'B':'W');puts("");
	for(int i=1;i<=m;i++)printf("%d\n",max(d[A[i]],d[B[i]]));
	return 0;
}
