#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=k;i<(ll)(n);i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
const ll inf=1001001001001001;
const int mod=998244353;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}

int main(){
    ll n,m;cin>>n>>m;
    vi v(n);
    rep(i,n)cin>>v[i];
    vector<vector<P>> g(n);
    vector<P> hen(m);
    vi ans(m,1000000000);
    vi c(n);
    rep(i,m){
        ll a,b;cin>>a>>b;a--;b--;
        hen[i].fi=a;hen[i].se=b;
        g[a].eb(b,i);
        g[b].eb(a,i);
        if(v[a]!=v[b]||(c[a]&&c[b]))continue;
        ans[i]=v[a];
        if(c[a])c[b]=3-c[a];
        else if(c[b])c[a]=3-c[b];
        else{
            c[a]=1;c[b]=2;
        }
    }
    vector<P> s(n);
    rep(i,n)s[i].fi=v[i];
    rep(i,n)s[i].se=i;
    sort(all(s));
    rep(i,n){
        if(c[s[i].se])continue;
        for(auto ne:g[s[i].se]){
            if(v[ne.fi]>s[i].fi)continue;
            c[s[i].se]=3-c[ne.fi];
            ans[ne.se]=s[i].fi;
            break;
        }
        if(!c[s[i].se]){
            out(-1);
            return 0;
        }
    }
    rep(i,n){
        if(c[i]==1)cout<<'B';
        else cout<<'W';
    }
    cout<<endl;
    rep(i,m)cout<<ans[i]<<endl;
}
