#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
void print() {}
template <class H, class... T>
void print(H&& h, T&&... t) {
  cout << h << " \n"[sizeof...(t) == 0];
  print(forward<T>(t)...);
}
ll U[200010], V[200010];
ll D[100010];
vector<ll> tree[100010];
map<lpair, ll> mp;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;
  for (ll i = (0); i < (N); i++) cin >> D[i];
  for (ll i = (0); i < (M); i++) {
    cin >> U[i] >> V[i];
    U[i]--;
    V[i]--;
    tree[U[i]].push_back(V[i]);
    tree[V[i]].push_back(U[i]);
    mp[{U[i], V[i]}] = i;
    mp[{V[i], U[i]}] = i;
  }
  ll weight[200010] = {};
  for (ll i = (0); i < (M); i++) {
    weight[i] = max(D[U[i]], D[V[i]]);
  }
  vector<lpair> lp;
  for (ll i = (0); i < (M); i++) {
    lp.push_back({weight[i], i});
  }
  ll color[100010] = {};
  sort(lp.begin(), lp.end(), greater<lpair>());
  bool ok = true;
  for (ll i = (0); i < (N); i++) {
    ll min_val = INF;
    for (auto& e : tree[i]) {
      ll idx = mp[{i, e}];
      min_val = min(min_val, weight[idx]);
    }
    if (min_val != D[i]) ok = false;
  }
  if (not ok) {
    print(-1);
    return 0;
  }
  for (ll i = (0); i < (M); i++) {
    ll idx = lp[i].second;
    if (color[U[idx]] == 0 && color[V[idx]] == 0) {
      color[U[idx]] = 1;
      color[V[idx]] = 2;
    } else if (color[U[idx]] == 0) {
      if (color[V[idx]] == 1) {
        color[U[idx]] = 2;
      } else {
        color[U[idx]] = 1;
      }
    } else if (color[V[idx]] == 0) {
      if (color[U[idx]] == 1) {
        color[V[idx]] = 2;
      } else {
        color[U[idx]] = 1;
      }
    }
  }
  for (ll i = (0); i < (N); i++) {
    if (color[i] == 1) {
      cout << 'B';
    } else {
      cout << 'W';
    }
  }
  cout << endl;
  for (ll i = (0); i < (M); i++) print(weight[i]);
}
