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

int main(){
	int N, M, i, j, k;
	scanf("%d%d", &N, &M);
	vector<int> D(N);
	vector<pair<int, int>> D_id(N);
	for(i = 0; i < N; i++){
		scanf("%d", &D[i]);
		D_id[i].first = D[i];
		D_id[i].second = i;
	}
	vector<vector<int>> g(N, vector<int>(0)), edge_id(N, vector<int>(0));
	for(i = 0; i < M; i++){
		int U, V;
		scanf("%d%d", &U, &V);
		U--;
		V--;
		g[U].push_back(V);
		edge_id[U].push_back(i);
		g[V].push_back(U);
		edge_id[V].push_back(i);
	}
	sort(D_id.begin(), D_id.end());
	vector<int> color(N, -1), C(M, -1);
	for(k = 0; k < N; k++){
		int d = D_id[k].first;
		i = D_id[k].second;
		int equal_less_than_count = 0;
		int O_near = 0;
		for(j = 0; j < g[i].size(); j++){
			if(D[g[i][j]] <= D[i]){
				equal_less_than_count++;
				C[edge_id[i][j]] = d;
			}
			if(color[g[i][j]] == 0){
				O_near = 1;
			}
		}
		if(equal_less_than_count == 0){
			printf("-1\n");
			return 0;
		}
		color[i] = O_near;
	}
	for(i = 0; i < N; i++){
		if(color[i] == 0){
			printf("W");
		}
		else{
			printf("B");
		}
	}
	printf("\n");
	for(i = 0; i < M; i++){
		printf("%d\n", C[i]);
	}
	return 0;
}