#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Tree = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
void co(const T n) {
  cout << n << endl;
}
template <typename T>
void cosp(const T n) {
  cout << n << ' ';
}
void coVec(const Vec &v) {
  for (ll i : v) cosp(i);
  cout << endl;
}
void sonic() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void setp(const ll n) { cout << fixed << setprecision(n); }
const ll INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const ll MOD = 1e9 + 7;
const ld PI = acos(-1);
const ld EPS = 1e-11;
Tree tree;
int main(void) {
  ll n, m;
  cin >> n >> m;
  tree.resize(n);
  Vec d(n);
  for (ll(i) = (0); (i) < (n); ++(i)) cin >> d[i];
  VecP e(n);
  for (ll(i) = (0); (i) < (n); ++(i)) {
    e[i].first = d[i];
    e[i].second = i;
  }
  sort((e).begin(), (e).end());
  for (ll(i) = (0); (i) < (m); ++(i)) {
    ll u, v;
    cin >> u >> v;
    u--;
    v--;
    tree[u].push_back({v, i});
    tree[v].push_back({u, i});
  }
  Vec color(n, 2);
  Vec cost(m);
  for (ll(i) = (0); (i) < (n); ++(i)) {
    P p = e[i];
    for (P j : tree[p.second]) {
      if (color[j.first] != 2) {
        color[p.second] = !color[j.first];
        cost[j.second] = p.first;
        break;
      }
    }
    if (color[p.second] == 2) {
      for (P j : tree[p.second]) {
        if (p.first == d[j.first]) {
          color[p.second] = 0;
          color[j.first] = 1;
          cost[j.second] = p.first;
          break;
        }
      }
    }
    if (color[p.second] == 2) {
      for (P j : tree[p.second]) {
        if (p.first >= d[j.first]) {
          color[p.second] = color[j.first];
          cost[j.second] = p.first - d[j.first];
          break;
        }
      }
    }
    if (color[p.second] == 2) {
      co(-1);
      return 0;
    }
  }
  for (ll(i) = (0); (i) < (m); ++(i))
    if (!cost[i]) cost[i] = 1e9;
  for (ll(i) = (0); (i) < (n); ++(i)) {
    if (!color[i])
      cout << "B";
    else
      cout << "W";
  }
  cout << endl;
  for (ll(i) = (0); (i) < (m); ++(i)) co(cost[i]);
  return 0;
}
