#include<bits/stdc++.h>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,M;
ll D[101010];
vector<pair<ll,pll>> uvv[101010];
ll ans[101010],ans2[202020];
vector<ll> sv[101010];
ll i, j;

//Union木
struct UnionFind{
    vector<int> nxt;
    void init(int x){
        nxt.clear();
        nxt.resize(x);
        for (int i = 0; i < x;i++){
            nxt[i] = i;
        }
    }
    int find(int x){
        if(nxt[x]==x)
            return x;
        return nxt[x] =find(nxt[x]);
    }
    inline void unite(int x,int y){
        nxt[find(y)] = find(x);
    }
};

void no(){
    printf("-1");
    exit(0);
}
void dfs(ll a,ll c){
    ll i = 0;
    ans[a] = c + 1;
    fornum(i,0,sv[a].size()){
        dfs(sv[a][i], c ^ 1);
    }
}

int main(){
    scanf("%lld%lld",&N,&M);
    fornum(i,0,N){
        scanf("%lld", &D[i + 1]);
    }


    fornum(i,0,M){
        ll u, v;
        scanf("%lld%lld", &u, &v);
        uvv[u].push_back({D[v], {v, i}});
        uvv[v].push_back({D[u], {u, i}});
    }

    fornum(i,0,N){
        sort(uvv[i + 1].begin(), uvv[i + 1].end());
        auto uv = uvv[i + 1][0];
        if(D[i+1]<uv.first){
            no();
        }
        if(ans2[uv.second.second]!=0&&ans2[uv.second.second]!=D[i+1]){
            no();
        }
        if(ans2[uv.second.second]==0){
            ans2[uv.second.second] = D[i + 1];
            sv[uv.second.first].push_back(i + 1);
            ans[i + 1] = 1;
        }
    }
    fornum(i,0,N){
        if (ans[i + 1] != 0)
            continue;
        dfs(i + 1, 0);
    }
    fornum(i,0,N){
        if(ans[i+1]==1){
            printf("B");
        }else{
            printf("W");
        }
    }
    fornum(i,0,M){
        printf("\n%lld", ans2[i] == 0 ? (ll)1e9 : ans2[i]);
    }
    

    
    return 0;
}