#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

constexpr int kMaxC = 1000000000;

struct Edge
{
    int u, v, c;
};

struct Node
{
    int i, d;
    char color;
    vector<Edge*> edges;
};

bool operator<(const Node& u, const Node& v)
{
    if (u.d != v.d) return u.d < v.d;
    if (u.i != v.i) return u.i < v.i;
    return false;
}

int main()
{
    int n, m; scanf("%d%d", &n, &m);
    vector<Node> nodes(n);
    for (int i = 0; i < n; i++) {
        int d; scanf("%d", &d);
        nodes[i] = {i, d, '?', {}};
    }
    vector<Edge> edges(m);
    for (int i = 0; i < m; i++) {
        int u, v; scanf("%d%d", &u, &v);
        edges[i] = {--u, --v, kMaxC};
        nodes[u].edges.push_back(&edges[i]);
        nodes[v].edges.push_back(&edges[i]);
    }

    sort(nodes.begin(), nodes.end());

    vector<Node*> sedon(n);
    for (int i = 0; i < n; i++)
        sedon[nodes[i].i] = &nodes[i];
    
    for (Node& v : nodes) {
        if (v.color != '?') continue;

        for (Edge* e : v.edges) {
            int u_i = (e->u != v.i) ? e->u : e->v;
            Node& u = *sedon[u_i];
            if (u.d == v.d || u.color != '?') {
                v.color = (u.color == 'B') ? 'W' : 'B';
                u.color = (v.color == 'B') ? 'W' : 'B';
                e->c = v.d;
                break;
            }
        }
        if (v.color == '?') {
            puts("-1");
            return 0;
        }
    }

    for (const Node* v : sedon)
        putchar(v->color);
    putchar('\n');
    for (const Edge& e : edges)
        printf("%d\n", e.c);

    return 0;
}
