#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1; char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int inf=1e9;
const int maxn=2e5+20;

struct Edge {
	int u,v,w;
};
Edge E[maxn];

int d[maxn],n,m,vis[maxn],col[maxn];
vector<int>ed[maxn];
queue<int>q;

inline void init()
{
	n=read();m=read();
	REP(i,1,n)d[i]=read();
	REP(i,1,m)
	{
		int u=read(),v=read();
		E[i]=(Edge){u,v,inf};
		if(d[u]==d[v] && !vis[u] && !vis[v])
			q.push(u),q.push(v),E[i].w=d[u],vis[u]=1,vis[v]=1,col[u]=1,col[v]=0;
		ed[u].push_back(i);
		ed[v].push_back(i);
	}
}

inline void doing()
{
	while(!q.empty())
	{
		int u=q.front();q.pop();
		for(int i:ed[u])
		{
			int v=E[i].u^E[i].v^u;
			if(d[v]>=d[u] && !vis[v])
				vis[v]=1,q.push(v),E[i].w=d[v],col[v]=col[u]^1;
		}
	}
	int s=0;
	REP(i,1,n)s+=vis[i];
	if(s==n)
	{
		REP(i,1,n)printf("%c",col[i]?'B':'W'); puts("");
		REP(i,1,m)printf("%d\n",E[i].w);
	}else puts("-1");
}

int main()
{
	init();
	doing();
	return 0;
}
