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

const int N = 1e5+7, INF = 1e9;
int d[N];
int col[N];

struct Edge {
    int u, v, w;
    Edge(int u, int v) :u(u), v(v), w(INF) {}
    int other(int x) {return u^v^x;}
};

vector<int> adj[N];
vector<Edge> edges;

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

    int n, m;
    cin>>n>>m;

    vector<int> order;

    for (int i=1; i<=n; i++)    {
        cin>>d[i];
        order.push_back(i);
    }

    auto comp = [](int x, int y) {return d[x] < d[y];};
    sort(order.begin(), order.end(), comp);

    for (int i=1; i<=m; i++) {
        int u, v;
        cin>>u>>v;
        edges.emplace_back(u, v);
        adj[u].push_back(edges.size()-1);
        adj[v].push_back(edges.size()-1);
    }

    for (int u: order) {
        if (col[u])    continue;
        bool found = false;
        for (int e: adj[u]) {
            int v = edges[e].other(u);
            if (col[v])  {
                edges[e].w = d[u];
                found = true;
                col[u] = 3 - col[v];
                break;
            }
        }

        if (!found) {
            for (int e: adj[u]) {
                int v = edges[e].other(u);
                if (d[v] == d[u]) {
                    edges[e].w = d[u];
                    found = true;
                    col[u] = 1;
                    col[v] = 2;
                    break;
                }
            }
        }
        if (!found) {
            cout<<-1<<endl;
            return 0;
        }
    }

    for (int i=1; i<=n; i++)
        if (col[i] == 1)    cout<<"W";
        else                cout<<"B";
    cout<<endl;
    for (int i=0; i<edges.size(); i++)  cout<<edges[i].w<<"\n";
}