// Optimise
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// #define MULTI_TEST
#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#define pc(...)
#endif

#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
auto TimeStart = chrono::steady_clock::now();
auto seed = TimeStart.time_since_epoch().count();
std::mt19937 rng(seed);
using ll = long long;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using Random = std::uniform_int_distribution<T>;

const int NAX = 2e5 + 5, MOD = 1000000007;

class Solution
{
private:
public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        int n, m;
        cin >> n >> m;
        vector<int> d(n);
        vector<pair<int, int>> sD(n);
        for (size_t i = 0; i < n; i++)
        {
            cin >> d[i];
            sD[i] = {d[i], i};
        }
        sort(all(sD));
        vector<vector<pair<int, int>>> adj(n);
        string S(n, 'W');
        vector<int> ans(m, MOD);
        for (size_t i = 0; i < m; i++)
        {
            int u, v;
            cin >> u >> v;
            --u, --v;
            adj[u].pb({v, i});
            adj[v].pb({u, i});
        }
        vector<bool> aaa(n, false);
        for (size_t i = 0; i < n; i++)
        {
            int node = sD[i].s;
            if (aaa[node])
                continue;
            bool ok = false;
            for (auto &it : adj[node])
            {
                auto child = it.f;
                if (d[child] <= d[node])
                {
                    if (S[child] == 'W')
                        S[node] = 'B';
                    else
                        S[node] = 'W';
                    if (d[child] == d[node])
                        aaa[child] = true;
                    ans[it.s] = d[child];
                    ok = true;
                    break;
                }
            }
            if (ok == false)
            {
                cout << -1 << '\n';
                return;
            }
        }
        cout << S << '\n';
        for (auto &x : ans)
            cout << x << '\n';
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
#ifdef MULTI_TEST
    cin >> t;
#endif
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef TIME
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}