#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<int(n); i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int N, M, INF = 1e9;
int used[100000], C[200000], S[100000];
vector<int> DD;
vector<P> G[100000];
vector<P> D;

int main(){
	cin >> N >> M;
	rep(i, N){ int d; cin >> d; D.push_back(P(d, i)); S[i] = -1; DD.push_back(d); }
	rep(i, M){
		int u, v; cin >> u >> v;
		u--; v--;
		G[u].push_back(P(v, i));
		G[v].push_back(P(u, i));
	}
	sort(ALL(D));
	rep(i, N){
		int now = D[i].second, f = 0;
		if(used[now]) continue;
		rep(j, G[now].size()){
			int to = G[now][j].first;
			if(DD[to] <= DD[now]){
				C[G[now][j].second] = DD[now];
				if(S[to] == -1) S[to] = 1;
				f = 1;
				S[now] = 1 - S[to];
				used[now] = 1;
				used[to] = 1;
				break;
			}
		}
		if(!f){ cout << -1 << endl; return 0; }
	}
	rep(i, N){
		if(S[i]) cout << 'W';
		else cout << 'B';
	}
	cout << "\n";
	rep(i, M){
		if(!C[i]) cout << INF << endl;
		else cout << C[i] << endl;
	}
	return 0;
}
