#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define x first
#define y second
#define pii pair<int , int>
#define sz(a) (int)(a.size())
const int INF = 1000 * 1000 * 1000;
const int mod = 998244353;
const int MAX = 1000 * 1000 + 47;
using namespace std;
vector<pair<int , int> > g[200005];
int izol = 0;
int sz[200005];
int p[200005];
int ans[200005];
int color[200005];
int find(int u)
{
	return p[u] = u == p[u] ? u : find(p[u]);
}
void unite(int u , int v)
{
	u = find(u) , v = find(v);
	if(u == v)
		return;
	izol -= sz[u] == 1;
	izol -= sz[v] == 1;
	sz[u] += sz[v];
	p[v] = u;
}
map<int , vector<int> > byD;
int main()
{
	memset(color , -1 , sizeof color);
	ios_base::sync_with_stdio(0);
	int n ,m;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		sz[i] = 1 , p[i] = i;
	for(int i = 0; i < n; i++)
	{
		int d;
		cin >> d;
		byD[d].pb(i);
	}
	for(int i = 0; i < m; i++)
	{
		int u , v;
		cin >> u >> v;
		u--;v--;
		g[u].pb({v , i});
		g[v].pb({u , i});
	}
	for(auto x : byD)
	{
		for(auto y : x.y)
		{
			izol++;
			bool allBlack = true;
			for(auto w : g[y])
			{
				allBlack &= color[w.x] != 0;
				if(color[w.x] != -1)
				{
					ans[w.y] = x.x;
					unite(y , w.x);
				}
			}
			color[y] = !allBlack;
		}
		if(izol)
		{
			cout << -1;
			return 0;
		}
	}
	for(int i = 0; i < n; i++)
		cout << (color[i] == 0 ? 'B' : 'W');
	cout << endl;
	for(int i = 0; i < m; i++)
		cout << ans[i] << endl;
}
