#include <bits/stdc++.h>
using ll = long long;
using P = std::pair<ll, ll>;
constexpr ll INF = 1ll << 60;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class S, class T>
std::ostream& operator<<(std::ostream& out, const std::pair<S, T>& a) {
  std::cout << '(' << a.first << ", " << a.second << ')';
  return out;
}
template <class T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& a) {
  std::cout << '[';
  for (ll i = (0); i < (a.size()); ++i) {
    std::cout << a[i];
    if (i != a.size() - 1) std::cout << ", ";
  }
  std::cout << ']';
  return out;
}
ll N, M;
ll D[100010];
std::vector<P> G[100010];
ll C[100010];
ll col[100010];
ll U[100010], V[100010];
int main() {
  std::cin >> N >> M;
  for (ll i = (0); i < (N); ++i) std::cin >> D[i];
  for (ll i = (0); i < (M); ++i) {
    std::cin >> U[i] >> V[i];
    --U[i];
    --V[i];
    G[U[i]].emplace_back(V[i], i);
    G[V[i]].emplace_back(U[i], i);
  }
  for (ll i = (0); i < (N); ++i) C[i] = 1e9;
  for (ll i = (0); i < (N); ++i) {
    bool fl = true;
    ll mi = INF;
    for (auto up : G[i]) {
      fl &= D[i] < D[up.first];
      chmin(mi, D[up.first]);
    }
    std::vector<ll> ids;
    for (auto up : G[i])
      if (D[up.first] == mi) {
        ids.emplace_back(up.second);
      }
    if (fl) {
      std::cout << -1 << std::endl;
      return 0;
    }
    for (auto idx : ids) C[idx] = D[i];
    for (ll c1 = (0); c1 < (2); ++c1)
      for (ll c2 = (0); c2 < (2); ++c2) {
        if (c1 + 1 == c2 + 1) continue;
        ll &ucol = col[U[i]], &vcol = col[V[i]];
        if (ucol && ucol == c2 + 1) continue;
        if (vcol && vcol == c1 + 1) continue;
        ucol = c1 + 1;
        vcol = c2 + 1;
      }
  }
  std::string S;
  for (ll i = (0); i < (N); ++i) S += (col[i] - 1 ? 'W' : 'B');
  std::cout << S << std::endl;
  for (ll i = (0); i < (M); ++i) std::cout << C[i] << std::endl;
  return 0;
}
