#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int n, m, d[MAX], ans[2*MAX];
vector<pii> G[MAX];
vector<int> H[MAX];

void dfs(int v, int pv, int col, string &s){
    if(s[v] != '#') return;
    s[v] = (col ? 'B' : 'W');
    for(int nv: H[v]) dfs(nv, v, col^1, s);
}

int main(){
    scanf("%d%d", &n, &m);
    rep(i, n) scanf("%d", &d[i]);
    rep(i, m){
        int u, v;
        scanf("%d%d", &u, &v);
        --u; --v;
        G[u].emplace_back(i, v);
        G[v].emplace_back(i, u);
    }
    fill(ans, ans+m, mod-7);
    rep(i, n){
        pii tmp = {d[i], mod}, te = {-1, -1};
        for(auto e: G[i]){
            if(chmin(tmp, {d[e.se], e.se})) te = e;
        }
        if(tmp.se == mod){
            puts("-1");
            return 0;
        }
        ans[te.fi] = max(d[i], d[te.se]);
        H[i].push_back(te.se);
        H[te.se].push_back(i);
    }
    string s(n, '#');
    rep(i, n) dfs(i, -1, 0, s);
    cout << s << "\n";
    rep(i, m) printf("%d\n", ans[i]);
}