#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> T;
 
long long int INF = 3e18;
const ll fact_table = 800008;
double Pi = 3.1415926535897932384626;
 
vector<P> G[550010];
vector<P> G2[550010];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
// priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
//ll mod = 998244353;
ll mod = 1000000007;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,a,b,c,d,e,g,h,i,j,q,r,l;
ll k;
ll ans;
ll x[500005], y[200005], z[200005];
bool edge_use[500005];
ll edge_cost[500005];
bool used[300005];
ll c_table[500005];

ll p[500005],ran[500005];

vector<T> edge;
vector<P> que; 

//木の根っこを求める
ll find(ll x){
    if(p[x]==x){
        return x;
    }else{
        return p[x] = find(p[x]);
    }
}

//ｘとｙの属する集合を併合
void unite(ll x,ll y, ll idx){
    G2[x].pb(P(y, idx));
    G2[y].pb(P(x, idx));
    edge.pb(T(P(x, y), idx));
    x = find(x);
    y = find(y);
    if(x==y)return;
    if(ran[x]<ran[y]){
        p[x]=y;
    }else{
        p[y]=x;
        if(ran[x]==ran[y])ran[x]++;
    }
}

void dfs(ll v,ll p,ll color){
    c_table[v] = color;
    for(ll i=0;i<G2[v].size();i++){
        ll nv = G2[v][i].first;
        ll edge_idx = G2[v][i].second;
        if(nv == p)continue;
        if(x[v-1] == x[nv-1]){
            edge_cost[edge_idx] = x[v-1];
            dfs(nv, v, 3 - color);
        }else if(x[v-1] > x[nv-1]){

            edge_cost[edge_idx] = x[v-1] - x[nv-1];
            dfs(nv, v, color);
        }else{
            edge_cost[edge_idx] = x[nv-1] - x[v-1];
            dfs(nv, v, color);
        }

    }
    return ;
}
int main(){
    /*
    cin.tie(0);
    ios::sync_with_stdio(false);
    */
    cin >> n >> m;
    for(ll i=0;i<n;i++){
        cin >> x[i];
    }
    for(ll i=1;i<=n;i++){
        p[i] = i;
    }
    for(ll i=0;i<m;i++){
        cin >> a >> b;
        y[i] = a;
        z[i] = b;
        G[a].pb(P(b, i));
        G[b].pb(P(a, i));
    }
    ll neededge = n - 1;
    for(ll i=1;i<=n;i++){
        ll mycost = x[i-1];
        bool dame = true;
        ll connect = -1;
        ll edge_idx = -1;
        for(ll j=0;j<G[i].size();j++){
            ll yourcost = x[G[i][j].first-1];
            if(yourcost <= mycost){
                dame = false;
                if((find(i) != find(G[i][j].first)) && neededge > 0){
                    connect = G[i][j].first;
                    edge_idx = G[i][j].second;
                }
            }
        }
        // 自分より小さいやつと絶対に繋ぐようにする
        if(connect != -1){
            unite(i, connect, edge_idx);
            neededge --;
        }
        if(dame){
            p(-1);
            return 0;
        }
    }

    for(ll i=0;i<m;i++){
        // 余っている辺を適当に繋ぐ
        if(neededge <= 0)break;
        if(find(z[i]) != find(y[i])){
            unite(z[i], y[i], i);
            neededge--;
        }
    }
    for(ll i=0;i<edge.size();i++){
        ll v1 = (edge[i].first).first;
        ll v2 = (edge[i].first).second;
        ll idx=  (edge[i].second);
        if(x[v1-1] == x[v2-1]){
            dfs(v1, v2, 1);
            dfs(v2, v1, 2);
            edge_cost[idx] = x[v1-1];
            break;
        }
    }
    for(ll i=1;i<=n;i++){
        if(c_table[i] == 1){
            pu("B");
        }else if(c_table[i] == 2){
            pu("W");
        }else{
            assert(0);
        }
    }
    el;
    for(ll i=0;i<m;i++){
         if(edge_cost[i] == 0 || edge_cost[i] == INF){
            p(1000000000);
        }else{
            p(edge_cost[i]);
        }
    }

    return 0;
}
 
 











Measured memory_bytes: 63664