#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <map>

const int mod = 1000000007;
//const int mod = 998244353;
int maximum(int a, int b) { return a < b ? b : a; }

int main() {
	long long N, M;
	scanf("%lld %lld", &N, &M);
	auto D = new int[N];
	for (int i = 0; i < N; i++) scanf("%d", D + i);
	auto U = new int[M];
	auto V = new int[M];
	std::map < long long, int>map;
	for (int i = 0; i < M; i++) {
		scanf("%d %d", U + i, V + i);
	}
	auto p = new std::vector<int>[N];
	for (int i = 0; i < M; i++) {
		U[i]--;
		V[i]--;
		p[U[i]].push_back(V[i]);
		p[V[i]].push_back(U[i]);
		map[U[i] * N + V[i]] = i;
		map[V[i] * N + U[i]] = i;
	}
	for (int i = 0; i < N; i++) {
		std::sort(p[i].begin(), p[i].end());
	}
	auto forest = new std::vector<int>[M];
	bool No = false;
	for (int i = 0; i < N; i++) {
		int min = 0;
		for (int j = 0; j < p[i].size(); j++) {
			if (D[p[i][j]] < D[p[i][min]]) {
				min = j;
			}
		}
		if (D[p[i][min]] > D[i]) {
			No = true;
			break;
		}
		forest[i].push_back(p[i][min]);
		forest[p[i][min]].push_back(i);
	}
	if (No) {
		printf("-1");
		return 0;
	}
	auto C = new char[N + 1]{};
	auto cost = new int[M] {};
	std::vector<int>q;
	int r = 0;
	for (int i = 0; i < N; i++) {
		if (C[i])continue;
		C[i] = 'B';
		q.push_back(i);
		while (q.size() > r) {
			for (int j = 0; j < forest[q[r]].size(); j++) {
				if (C[forest[q[r]][j]])continue;
				C[forest[q[r]][j]] = C[q[r]] == 'B' ? 'W' : 'B';
				cost[map[q[r] * N + forest[q[r]][j]]] = maximum(D[q[r]], D[forest[q[r]][j]]);
				q.push_back(forest[q[r]][j]);
			}
			r++;
		}
	}
	for (int i = 0; i < M; i++) {
		if (cost[i] == 0) {
			cost[i] = 1000000000;
		}
	}
	printf(C);
	for (int i = 0; i < M; i++) {
		printf("\n%d", cost[i]);
	}
	return 0;
}