#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int INF=(1e9);
const int maxn=(4e5)+10;
int n,m,ans[maxn];
int d[maxn],op[maxn];
vector<int> g[maxn],id[maxn];
void add(int x,int y,int z) {
	g[x].push_back(y);
	id[x].push_back(z);
}
pair<int,int> p[maxn];
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(m);
	int x,y,z,flag;
	for (int i=1;i<=n;i++) read(d[i]),p[i]=make_pair(d[i],i),op[i]=-1;
	sort(p+1,p+n+1);
	for (int i=1;i<=m;i++) read(x),read(y),add(x,y,i),add(y,x,i);
	for (int I=1,u;I<=n;I++) {
		u=p[I].second;
		if (op[u]>-1) continue;
		flag=0;
		for (int i=0,v;i<g[u].size();i++) {
			v=g[u][i]; z=id[u][i];
			if (d[u]>=d[v]) {
				flag=1;
				if (op[v]==-1) op[v]=0,op[u]=1;
				else op[u]=op[v]^1;
				ans[z]=d[u];
				break;
			}
		}
		if (!flag) { printf("-1\n"); return 0; }
	}
	for (int i=1;i<=n;i++)
		if (op[i]) printf("B");
		else printf("W");
	printf("\n");
	for (int i=1;i<=m;i++) {
		if (!ans[i]) ans[i]=INF;
		printf("%d\n",ans[i]);
	}
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/