#include <bits/stdc++.h>
using namespace std;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, m;
    static pair<int64_t, int> weight[100000];
    static int w[100000];
    static char color[100001];
    static int ans[200000];
    static vector<tuple<int64_t, int, int>> edges[100000];
    cin >> n >> m;
    for(int i=0;i<n;++i){
        int d;
        cin >> d;
        weight[i] = {d, i};
        w[i] = d;
    }
    for(int i=0;i<m;++i){
        int u, v;
        cin >> u >> v;
        --u; --v;
        edges[u].emplace_back(weight[v].first, v, i);
        edges[v].emplace_back(weight[u].first, u, i);
    }
    sort(weight, weight + n);
    for(int i=0;i<n;++i) sort(edges[i].begin(), edges[i].end());

    for(int i=0;i<n;++i){
        int v = weight[i].second, to = get<1>(edges[v][0]), e = get<2>(edges[v][0]);
        if(color[v] != 0) continue;
        if(color[to] != 0){
            color[v] = 'W' + 'B' - color[to];
            ans[e] = w[v];
        }else{
            cerr << to << " " << v << endl;
            if(w[to] != w[v]){ cout << -1 << endl; return 0; }
            color[v] = 'W'; color[to] = 'B';
            ans[e] = w[v];
        }
    }
    cout << color << endl;
    for(int i=0;i<m;++i) cout << (ans[i] == 0 ? 1000000000 : ans[i]) << endl;

    return 0;
}