#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M = 2e5+5;
int d[M],U[M],V[M],col[M],wt[M];
vector<int> vtr[M];
int adj(int x,int e)
{
	return U[e]+V[e]-x;
}
int main()
{
	int n,m;
	cin>>n>>m;
	vector<pair<int,int>> vec;
	for(int i=1;i<=n;i++)
	{
		cin>>d[i];
		vec.pb({d[i],i});
	}
	sort(all(vec));
	for(int i=1;i<=m;i++)
	{
		cin>>U[i]>>V[i];
		vtr[U[i]].pb(i);
		vtr[V[i]].pb(i);
	}
	// col => 1-2
	// wt => 1-1e9
	for(int i=1;i<=m;i++)
	{
		int u = U[i],v = V[i];
		if(col[u] && col[v])
			continue;
		if(d[u]!=d[v])
			continue;
		if(col[u])
			col[v] = 1-col[u];
		else if(col[v])
			col[u] = 1 - col[v];
		else
		{
			col[u] = 1;
			col[v] = 2;
		}
		wt[i] = d[u];
	}
	for(auto u:vec)
	{
		int x = u.ss;
		if(col[x])
			continue;
		for(auto ed:vtr[x])
		{
			int v = adj(x,ed);
			if(col[v] && d[v]<=d[x])
			{
				col[x] = 3-col[v];
				wt[ed] = d[x];
				break;
			}
		}
	}
	string s;
	for(int i=1;i<=n;i++)
	{
		if(col[i]==0)
		{
			cout<<"-1\n";
			return 0;
		}
		if(col[i]==1)
			s.pb('W');
		else
			s.pb('B');
	}
	cout<<s<<"\n";
	for(int i=1;i<=m;i++)
	{
		if(wt[i]==0)
			wt[i] = 1e9;
		cout<<wt[i]<<"\n";
	}
	return 0;
}