#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int N = 1e5;
const int M = 2 * (int)1e5;
vector<int> conns[N];
int dist[M];
int dep[N];

void dfs(int i, string& col) {
	for (int t : conns[i]) {
		if (dep[t] >= dep[i] && col[t] == '_') {
			col[t] = (col[i] == 'W' ? 'B' : 'W');
			dfs(t, col);
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, m;
	cin >> n >> m;

	vector<pair<int, int>> ds(n);
	for (int i = 0; i < n; ++i) {
		cin >> dep[i];
		ds[i] = {dep[i], i};
	}
	sort(ds.begin(), ds.end());
	int d0 = ds[0].first;

	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		conns[a].push_back(b);
		conns[b].push_back(a);
		dist[i] = max(dep[a], dep[b]);
	}

	bool fail = false;
	string col(n, '_');
	for (auto pr : ds) {
		int i = pr.second;
		if (col[i] == '_') {
			col[i] = 'W';
			dfs(i, col);
		}
		bool works = false;
		for (int t : conns[i]) works |= (dep[t] <= dep[i]);
		fail |= !works;
	}

	if (fail) {
		cout << -1 << '\n';
	} else {
		cout << col << '\n';
		for (int i = 0; i < m; ++i) cout << dist[i] << ' '; cout << '\n';
	}
}
