#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
void init_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main() {
  init_io();
  ll n, m;
  map<P, ll> mp;
  cin >> n >> m;
  vector<P> d(n);
  vector<ll> G[n];
  vector<char> s(n, 'X');
  vector<ll> u(m), v(m);
  for (int i = 0; i < n; i++) {
    cin >> d[i].first;
    d[i].second = i;
  }
  for (int i = 0; i < m; i++) {
    cin >> u[i] >> v[i];
    u[i]--;
    v[i]--;
    G[u[i]].push_back(v[i]);
    G[v[i]].push_back(u[i]);
  }
  sort(d.begin(), d.end());
  if (d[0].first != d[1].first) {
    cout << "-1\n";
    return 0;
  }
  s[d[0].second] = 'B';
  s[d[1].second] = 'W';
  mp[P(min(d[0].second, d[1].second), max(d[0].second, d[1].second))] =
      d[0].first;
  for (int i = 2; i < n; i++) {
    ll v = d[i].second;
    bool add = false;
    for (auto nv : G[v]) {
      ll fi = min(nv, v);
      ll si = max(nv, v);
      auto it = mp.find(P(fi, si));
      if (it == mp.end() || it->second == d[i].first) {
        add = true;
        char c = s[nv];
        if (c == 'B')
          c = 'W';
        else
          c = 'B';
        s[v] = c;
        mp[P(fi, si)] = d[i].first;
        break;
      }
    }
    if (!add) {
      cout << "-1\n";
      return 0;
    }
  }
  for (auto c : s) {
    cout << c;
  }
  cout << endl;
  for (int i = 0; i < m; i++) {
    ll fi = min(u[i], v[i]);
    ll si = max(u[i], v[i]);
    ll ans;
    auto it = mp.find(P(fi, si));
    if (it == mp.end()) {
      ans = 1000000000;
    } else {
      ans = it->second;
    }
    cout << ans << endl;
  }
}
