#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int N=500005;
int n,m,v1[N],x[N],y[N],co[N],ans[N];
pii v2[N];
vector<int> e[N];
void color(int x){
	for (auto i:e[x]) if (!co[i])
		co[i]=co[x]^3,color(i);
}
int main(){
	scanf("%d%d",&n,&m);
	For(i,1,n){
		scanf("%d",&v1[i]);
		v2[i].fi=1ll<<30;
	}
	For(i,1,m){
		scanf("%d%d",&x[i],&y[i]);
		v2[y[i]]=min(v2[y[i]],pii(v1[x[i]],i));
		v2[x[i]]=min(v2[x[i]],pii(v1[y[i]],i));
	}
	For(i,1,n) if (v2[i].fi>v1[i]) return puts("-1"),0;
	For(i,1,m) ans[i]=1000000000;
	For(i,1,n) ans[v2[i].se]=v1[i];
	For(i,1,n) e[x[v2[i].se]].PB(y[v2[i].se]);
	For(i,1,n) e[y[v2[i].se]].PB(x[v2[i].se]);
	For(i,1,n) if (co[i]==0) co[i]=1,color(i);
	For(i,1,n) putchar(co[i]==1?'B':'W');
	puts("");
	For(i,1,m) printf("%d\n",ans[i]);
}