#include <bits/stdc++.h>

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

struct edge{
	int from, to;
	edge(int from, int to):from(from), to(to){}
};
using node = vector<edge>;
using graph = vector<node>;
void addedge(graph &g, int from, int to, bool bidirectional = false){
	g[from].emplace_back(edge(from, to));
	if(bidirectional)g[to].emplace_back(edge(to, from));
}

class Solution {
public:
	void No(){
		cout << -1 << endl;
		return;
	}

	void solve() {
		int n, m;
		cin >> n >> m;
		vector<int> d(n);
		vector<pair<int,int>> di(n);
		for(int i=0; i<n; i++)cin >> d[i];
		for(int i=0; i < n; i++)di[i] = make_pair(d[i], i);
		sort(di.begin(), di.end());
		if(di[0].first != di[1].first)return No();
		vector<int> color(n, -1);
		map<pair<int, int>, int> etoi;
		graph g(n);
		for(int i=0; i < m; i++){
			int u, v;
			cin >> u >> v;
			u--, v--;
			etoi[make_pair(u, v)] = i;
			etoi[make_pair(v, u)] = i;
			addedge(g, u, v, true);
		}
		vector<int> w(m, 1000000000);
		for(int i=0; i < n; i++){
			int u = di[i].second;
			int x = di[i].first;
			if(color[u] != -1)continue;
			for(auto e:g[u]){
				if(color[e.to] != -1){
					color[u] = 1-color[e.to];
					w[etoi[make_pair(u, e.to)]] = x;
					break;
				}
				else if(d[u] == d[e.to]){
					color[u] = 0;
					color[e.to] = 1;
					w[etoi[make_pair(u, e.to)]] = x;
					break;					
				}
			}
			if(color[u] == -1)return No();
		}
		for(int i=0; i < n; i++){
			if(color[i])cout << "B";
			else cout << "W";
		}
		cout << "\n";
		for(int i=0; i<m; i++)cout << w[i] << " ";
		cout << "\n";
		
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}