#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
constexpr int N = 100'000, M = 200'000, INF = 1'000'000'000;
int n, m;
int d[N], color[N], w[M], perm[N];
std::vector<std::pair<int, int>> e[N];
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> n >> m;
    for (int i = 0; i < n; ++i)
        std::cin >> d[i];
    std::fill(color, color + n, -1);
    std::fill(w, w + m, INF);
    for (int i = 0; i < m; ++i) {
        int u, v;
        std::cin >> u >> v;
        --u;
        --v;
        if (color[u] == -1 && color[v] == -1 && d[u] == d[v]) {
            color[u] = 0;
            color[v] = 1;
            w[i] = d[u];
        }
        e[u].emplace_back(v, i);
        e[v].emplace_back(u, i);
    }
    std::queue<int> que;
    for (int i = 0; i < n; ++i)
        if (color[i] != -1)
            que.push(i);
    while (!que.empty()) {
        int u = que.front();
        que.pop();
        for (auto [v, i] : e[u]) {
            if (color[v] == -1 && d[v] >= d[u]) {
                color[v] = color[u] ^ 1;
                w[i] = d[v];
                que.push(v);
            }
        }
    }
    std::string s;
    for (int i = 0; i < n; ++i) {
        if (color[i] == -1) {
            std::cout << -1 << "\n";
            return 0;
        }
        if (color[i] == 0) {
            s += 'W';
        } else {
            s += 'B';
        }
    }
    std::cout << s << "\n";
    for (int i = 0; i < m; ++i)
        std::cout << w[i] << "\n";
    return 0;
}