#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
using namespace std;
typedef long long ll;

const ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

int n, m, d[100009], u[200009], v[200009];

vector<int> e[100009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    cin >> n >> m;

    vector<int> ans(m, 1e9), mn(n, 1e9 + 1), num(n);
    vector<char> c(n, '?');

    rep(i, n) cin >> d[i];
    rep(i, m) {
        cin >> u[i] >> v[i];
        u[i]--;
        v[i]--;
        if(chmin(mn[u[i]], d[v[i]])) num[u[i]] = i;
        if(chmin(mn[v[i]], d[u[i]])) num[v[i]] = i;
    }
    rep(i, n) {
        if(mn[i] > d[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans[num[i]] = d[i];
        int x = (u[num[i]] == i ? v : u)[num[i]];
        e[i].push_back(x);
        e[x].push_back(i);
    }
    queue<int> que;
    rep(i, n) {
        if(c[i] == '?') {
            c[i] = 'B';
            que.push(i);
            while(!que.empty()) {
                int x = que.front();
                que.pop();
                rep(i, e[x].size()) {
                    if(c[e[x][i]] == '?') {
                        c[e[x][i]] = (c[x] == 'B' ? 'W' : 'B');
                        que.push(e[x][i]);
                    }
                }
            }
        }
        cout << c[i];
    }
    rep(i, m) cout << endl << ans[i];
}