#include <bits/stdc++.h>
using namespace std;

const int INF = 1000000000;

typedef pair<int,int> P;

#define fr first
#define sc second

int main(){
	static int n,m;
	static int d[100010];
	static int a[200010],b[200010];
	scanf("%d%d",&n,&m);
	for(int i = 1 ; i <= n ; i ++){
		scanf("%d",&d[i]);
	}
	for(int i = 1 ; i <= m ; i ++){
		scanf("%d%d",&a[i],&b[i]);
	}
	
	vector<int> G[100010];
	for(int i = 1 ; i <= m ; i ++){
		G[a[i]].push_back(b[i]);
		G[b[i]].push_back(a[i]);
	}
	
	vector<P> vec;
	for(int i = 1 ; i <= n ; i ++){
		vec.push_back(P(d[i],i));
	}
	sort(vec.begin(),vec.end());
	
	static int color[100010] = {};
	map<P,int> M;
	for(int i = 0 ; i < vec.size() ; i ++){
		int v = vec[i].sc;
		if(color[v] != 0)continue;
		int u = -1;
		for(int j = 0 ; j < G[v].size() ; j ++){
			if(d[G[v][j]] <= d[v]){
				u = G[v][j];
				break;
			}
		}
		if(u == -1){
			puts("-1");
			return 0;
		}
		if(color[u] == 0)color[u] = 1;
		color[v] = -color[u];
		M[P(u,v)] = d[v];
		M[P(v,u)] = d[v];
	}
	
	for(int i = 1 ; i <= n ; i ++){
		if(color[i] == 1)printf("B");
		else printf("W");
	}
	cout << endl;
	for(int i = 1 ; i <= m ; i ++){
		map<P,int>::iterator itr = M.find(P(a[i],b[i]));
		if(itr == M.end()){
			printf("%d\n",INF);
		}
		else printf("%d\n",itr->sc);
	}
}