#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int n, m;
ll d[100000];
vector<pi> e[100000];
string ans;
vector<int> anse;

bool cmp (const int& l, const int& r) {
    return d[l] < d[r];
}

bool cmp2 (const pi& l, const pi& r) {
    return d[l.first] < d[r.first];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    rep(i,n) cin >> d[i];
    rep(i,n) ans.push_back('B');
    anse.resize(m);
    rep(i,m) anse[i] = -1;
    rep(i,m) {
        int u, v; cin >> u >> v; u--; v--;
        e[u].push_back(pi(v,i));
        e[v].push_back(pi(u,i));
    }
    rep(i,n) sort(e[i].begin(), e[i].end(), cmp2);
    vector<int> ind(n);
    vector<int> fixed(n, 0);
    rep(i,n) ind[i] = i;
    sort(ind.begin(), ind.end(), cmp);
    rep(_,n) {
        int i = ind[_];
        if (d[e[i][0].first] > d[i]) {
            puts("-1");
            return 0;
        }
        rep(j,e[i].size()) {
            int to = e[i][j].first;
            if (d[to] > d[i]) {
                break;
            }
            if (!fixed[i]) {
                if (ans[to] == 'B') ans[i] = 'W';
                else ans[i] = 'B';
                fixed[i] = true;
                fixed[to] = true;
            }
            anse[e[i][j].second] = d[i];
        }
    }
    cout<< ans << endl;
    rep(i,m) cout << anse[i] << endl;
}