#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<pair<int, int> > A(N);
	vector<int> D(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i].first;
		D[i] = A[i].first;
		A[i].second = i;
	}
	vector<vector<pair<int, int> > > g(N);
	int INF = 1000000000;
	vector<int> res(M, INF);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].emplace_back(b, i);
		g[b].emplace_back(a, i);
	}
	sort(A.begin(), A.end());
	string col(N, '.');
	for (int i = 0; i < N; i++) {
		int val = A[i].first;
		int idx = A[i].second;
		if (col[idx] != '.') continue;
		bool ok = false;
		for (const pair<int, int> &p : g[idx]) {
			if (col[p.first] != '.') {
				col[idx] = (col[p.first] == 'B' ? 'W' : 'B');
				res[p.second] = val;
				ok = true;
				break;
			}
		}
		if (!ok) {
			queue<int> qu;
			qu.push(idx);
			col[idx] = 'B';
			while (qu.size() > 0) {
				int a = qu.front();
				qu.pop();
				for (const pair<int, int> &p : g[a]) {
					if (col[p.first] == '.') {
						if (D[p.first] == val) {
							col[p.first] = (col[a] == 'B' ? 'W' : 'B');
							res[p.second] = val;
							ok = true;
							qu.push(p.first);
						}
					}
				}
			}
		}
		if (!ok) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << col << endl;
	for (int i = 0; i < M; i++) {
		cout << res[i] << endl;
	}
}