#include <bits/stdc++.h>

using namespace std;

int n, m;
string S;
const int INF = 1e9;
vector<int64_t> D;
vector<vector<array<int, 3>>> E;
vector<int> C;
vector<bool> visited, changed, cleared;

bool dfs(int v, bool color){
    if (visited[v])
        return true;
    visited[v] = true;
    S[v] = color ? 'B' : 'W';
    for (const auto &e: E[v]){
        auto to = e[1];
        if (C[e[2]] == D[v]){
            cleared[v] = true;
        }
        if (S[to] != 'a' and S[to] != S[v] and C[e[2]] < D[v])
            return false;
        if (!cleared[v] and !changed[e[2]]){
            C[e[2]] = D[v];
            changed[e[2]] = true;
            cleared[v] = true;
        }
        if (!dfs(to, 1 - color))
            return false;
    }
    return true;
}

int main(){
    cin >> n >> m;
    D.resize(n);
    copy_n(istream_iterator<int64_t>(cin), n, D.begin());
    E.resize(n);
    for (int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        E[u].push_back({D[v], v, i});
        E[v].push_back({D[u], u, i});
    }
    
    for (int i = 0; i < n; i++)
        sort(E[i].begin(), E[i].end());
    for (int i = 0; i < n; i++)
        S.push_back('a');

    C.assign(n, INF);

    int min_v = 0;
    for (int i = 0; i < n; i++){
        if (D[min_v] > D[i])
            min_v = i;
    }

    visited.resize(n);
    changed.resize(m);
    cleared.resize(n);

    if (dfs(min_v, false)){
        cout << S << endl;
        for (const auto &c: C)
            cout << c << endl;
    } else {
        puts("-1");
    }
}