#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int d[500010],n,m,c[500010],p[500010],e[500010],x[500010],y[500010];
bool ok[500010];
bool cmp(int A,int B){
	return (d[y[A]]<d[y[B]] || d[y[A]]==d[y[B]] && d[x[A]]<d[x[B]]);
}
int main(){
	cin>>n>>m;
	FOR(i,1,n) getint(d[i]);
	FOR(i,1,m){
		getint(x[i]),getint(y[i]);
		if (d[x[i]]>d[y[i]]) swap(x[i],y[i]);
		if (d[y[i]]<=d[x[i]]) ok[x[i]]=1;
		if (d[x[i]]<=d[y[i]]) ok[y[i]]=1;
	}
	FOR(i,1,n) if (!ok[i]) return puts("-1"),0;
	FOR(i,1,m) p[i]=i;
	sort(p+1,p+m+1,cmp);
	memset(c,-1,sizeof(c));
	FOR(i,1,m){
		int h=p[i];
		if (c[x[h]]==-1 && c[y[h]]==-1){
			c[x[h]]=0;
			c[y[h]]=1;
		}
		else if (c[x[h]]==-1)
			c[x[h]]=c[y[h]]^1;
		else if (c[y[h]]==-1)
			c[y[h]]=c[x[h]]^1;
		e[h]=max(d[x[h]],d[y[h]]);
	}
	FOR(i,1,n) if (c[i]==0) putchar('W'); else putchar('B');
	puts("");
	FOR(i,1,m) printf("%d\n",e[i]);
	return 0;
}