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

using Graph = vector<vector<int>>;
using P = pair<int, int>;
#define INF 1000000000

void ch(int &x, int &y){
    if(y < x){
        int tmp = y;
        y = x;
        x = tmp;
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int>D(N+1);
    vector<P>DS(N);
    for (int i = 1; i <= N; ++i) {
        cin >> D[i];
        DS[i-1] = P(D[i], i);
    }
    sort(DS.begin(), DS.end());
    Graph graph(N+1);
    map<P, int>mp;
    vector<int>U(M);
    vector<int>V(M);
    for (int i = 0; i < M; ++i) {
        cin >> U[i] >> V[i];
        ch(U[i], V[i]);
        mp[P(U[i], V[i])] = INF;
        graph[U[i]].push_back(V[i]);
        graph[V[i]].push_back(U[i]);
    }

    vector<int>ans(N+1, 0);
    for (int i = 0; i < N; ++i) {
        int v = DS[i].second;
        int cs = DS[i].first;
        if (ans[v]) continue;
        int flag = 0;
        for (int x: graph[v]) {
            if (ans[x] != 0) {
                int t1 = v;
                int t2 = x;
                ch(t1, t2);
                mp[P(t1, t2)] = cs;
                flag = 1;
                if (ans[x] == 1) ans[v] = 2;
                else ans[v] = 1;
                break;
            }
        }
        if (flag) continue;
        for (int x: graph[v]) {
            if (D[x] == cs) {
                flag = 1;
                ans[v] = 1;
                ans[x] = 2;
                int t1 = v;
                int t2 = x;
                ch(t1, t2);
                mp[P(t1, t2)] = cs;
                break;
            }
        }
        if (flag) continue;

        cout << -1 << "\n";
        return 0;
    }

    for (int i = 1; i <= N; ++i) {
        if (ans[i] == 1) {
            cout << "W";
        } else {
            cout << "B";
        }
    }
    cout << "\n";
    for (int i = 0; i < M; ++i) {
        cout << mp[P(U[i], V[i])] << "\n";
    }
    return 0;
}