#include <bits/stdc++.h>
void solve();
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <typename T>
inline T power(T x, LL n) {
  T r(1);
  for (; n; n /= 2) {
    if (n % 2) r *= x;
    x *= x;
  }
  return r;
}
inline LL pow_mod(LL x, LL n, LL m) {
  LL r = 1;
  for (; n; n /= 2) {
    if (n % 2) r = r * x % m;
    x = x * x % m;
  }
  return r;
}
inline constexpr LL modulo(LL a, LL b) {
  a %= b;
  return a && (a > 0) != (b > 0) ? a + b : a;
}
inline constexpr LL divide(LL a, LL b) { return (a - modulo(a, b)) / b; }
template <LL d = 1000000007>
struct MInt {
  LL v;
  constexpr MInt() : v(0) {}
  explicit constexpr MInt(LL i) : v(modulo(i, d)) {}
  MInt& operator+=(const MInt& m) {
    v += m.v;
    if (v >= d) v -= d;
    return *this;
  }
  MInt& operator-=(const MInt& m) {
    v -= m.v;
    if (v < 0) v += d;
    return *this;
  }
  MInt& operator*=(const MInt& m) {
    v = v * m.v % d;
    return *this;
  }
  MInt& operator/=(const MInt& m) { return *this *= m.inv(); }
  MInt operator+(const MInt& o) const { return MInt(*this) += o; }
  MInt operator-(const MInt& o) const { return MInt(*this) -= o; }
  MInt operator*(const MInt& o) const { return MInt(*this) *= o; }
  MInt operator/(const MInt& o) const { return MInt(*this) /= o; }
  MInt operator-() const { return MInt() -= *this; }
  bool operator==(const MInt& m) const { return v == m.v; }
  bool operator!=(const MInt& m) const { return v != m.v; }
  MInt pow(LL n) const { return power(*this, n); }
  MInt inv() const {
    LL a = v, b = d, x = 1, y = 0;
    while (b) {
      swap(y, x -= a / b * y);
      swap(b, a %= b);
    }
    return (MInt)x;
  }
  friend ostream& operator<<(ostream& o, const MInt& m) { return o << m.v; }
  friend istream& operator>>(istream& i, MInt& m) {
    i >> m.v;
    m.v %= d;
    return i;
  }
};
using mint = MInt<>;
constexpr mint operator"" _m(ULL n) { return mint(n); }
constexpr MInt<998244353> operator"" _m998244353(ULL n) {
  return MInt<998244353>(n);
}
constexpr MInt<1000000007> operator"" _m1e9_7(ULL n) {
  return MInt<1000000007>(n);
}
constexpr MInt<1000000009> operator"" _m1e9_9(ULL n) {
  return MInt<1000000009>(n);
}
using unit = tuple<>;
using LD = long double;
template <typename T>
using vec = vector<T>;
template <typename T>
using vvec = vec<vec<T>>;
template <typename T>
using vvvec = vec<vvec<T>>;
template <typename T>
using vvvvec = vec<vvvec<T>>;
using VI = vec<LL>;
using WI = vvec<LL>;
using VB = vec<bool>;
using HPIII = map<pair<LL, LL>, LL>;
using VPII = vec<pair<LL, LL>>;
template <typename T>
inline bool amax(T& v, const T& a) {
  return v < a && (v = a, 1);
}
template <typename T>
inline bool amin(T& v, const T& a) {
  return v > a && (v = a, 1);
}
template <typename T>
inline LL sizeRAB(T t) {
  return t.size();
}
template <typename T>
inline constexpr const T& clampRAB(const T& a, const T& l, const T& r) {
  return a < l ? l : r < a ? r : a;
}
template <typename V>
inline void uniq2(V& v) {
  v.erase(unique(begin(v), end(v)), v.end());
}
template <typename V>
inline void uniq(V& v) {
  sort(begin(v), end(v));
  uniq2(v);
}
template <typename C, typename D>
inline C rightmost_le(const C& from, const C& to, const D& d) {
  auto l = upper_bound(from, to, d);
  return l == from ? to : --l;
}
template <typename C, typename D>
inline C rightmost_lt(const C& from, const C& to, const D& d) {
  auto l = lower_bound(from, to, d);
  return l == from ? to : --l;
}
namespace rab {
template <typename I>
inline bool is_in(I x, I l, I r) {
  return l <= x && x < r;
}
template <typename T>
inline T fetch(const T& d, const vec<T>& v, LL i) {
  return 0 <= i && i < sizeRAB(v) ? v[i] : d;
}
}  // namespace rab
template <typename T>
inline istream& operator>>(istream& s, vec<T>& v) {
  for (auto&& p : v) s >> p;
  return s;
}
template <typename T, typename S>
inline ostream& operator<<(ostream& s, const pair<T, S>& p) {
  return s << "(" << p.first << "," << p.second << ")";
}
template <typename T>
inline ostream& operator<<(ostream& s, const vec<T>& v) {
  LL i = 0;
  for (const auto& e : v) {
    i++&& s << ' ';
    s << e;
  }
  return s;
}
template <typename T, typename S>
inline ostream& operator<<(ostream& s, const map<T, S>& v) {
  LL i = 0;
  for (const auto& e : v) {
    i++&& s << ' ';
    s << e;
  }
  return s;
}
template <typename T>
inline ostream& operator<<(ostream& s, const vvec<T>& v) {
  LL i = 0;
  for (const auto& e : v) {
    i++&& s << '\n';
    s << e;
  }
  return s;
}
template <typename T, typename S>
inline ostream& operator<<(ostream& s, const vec<map<T, S>>& v) {
  LL i = 0;
  for (const auto& e : v) {
    i++&& s << '\n';
    s << e;
  }
  return s;
}
signed main() {
  if (false)
    cerr << "MOD: " << 1000000007 << '\n';
  else
    cin.tie(0), cerr.tie(0), ios::sync_with_stdio(0);
  auto p = setprecision(20);
  cout << fixed << p;
  cerr << fixed << p;
  solve();
  return 0;
}
void solve() {
  LL N;
  LL M;
  cin >> N;
  cin >> M;
  VI D(N);
  for (LL Rb_ = (N), Ri_0 = (0); Ri_0 < Rb_; ++(Ri_0)) {
    cin >> D[Ri_0];
  }
  VI U(M);
  VI V(M);
  for (LL Rb_ = (M), Ri_0 = (0); Ri_0 < Rb_; ++(Ri_0)) {
    cin >> U[Ri_0];
    --U[Ri_0];
    cin >> V[Ri_0];
    --V[Ri_0];
  }
  WI edges(N);
  for (LL Rb_ = (M), j = (0); j < Rb_; ++(j)) {
    edges[U[j]].push_back(V[j]);
    edges[V[j]].push_back(U[j]);
  }
  VB used(N);
  VB black(N);
  HPIII costs;
  VPII DI(N);
  for (LL Rb_ = (N), i = (0); i < Rb_; ++(i)) DI[i] = make_pair(D[i], i);
  sort(begin(DI), end(DI));
  for (LL Rb_ = (N), h = (0); h < Rb_; ++(h)) {
    LL d, i;
    tie(d, i) = DI[h];
    if (used[i]) continue;
    used[i] = true;
    LL deg = 0;
    for (LL j : edges[i]) deg += used[j];
    if (deg == 0) {
      LL fr = -1;
      for (LL j : edges[i])
        if (D[i] == D[j]) fr = j;
      if (fr == -1) {
        cout << -1 << '\n';
        return;
      }
      black[i] = true;
      used[fr] = true;
      black[fr] = false;
      costs[make_pair(i, fr)] = costs[make_pair(fr, i)] = d;
    } else if (deg == 1) {
      LL nb = -1;
      for (LL j : edges[i])
        if (used[j]) nb = j;
      assert(nb >= 0);
      if (D[nb] == D[i]) {
        black[i] = !black[nb];
        costs[make_pair(i, nb)] = costs[make_pair(nb, i)] = D[i];
      } else {
        black[i] = black[nb];
        costs[make_pair(i, nb)] = costs[make_pair(nb, i)] = D[i] - D[nb];
      }
    } else {
      LL nb = -1;
      for (LL j : edges[i])
        if (used[j] && D[i] != D[j]) nb = j;
      if (nb == -1) {
        LL fr = -1;
        for (LL j : edges[i])
          if (used[j]) fr = j;
        assert(fr >= 0);
        black[i] = !black[fr];
        for (LL j : edges[i])
          if (used[j]) {
            costs[make_pair(i, j)] = costs[make_pair(j, i)] = D[i];
          }
      } else {
        black[i] = black[nb];
        for (LL j : edges[i])
          if (used[j]) {
            costs[make_pair(i, j)] = costs[make_pair(j, i)] =
                (j == nb ? D[i] - D[nb] : D[i]);
          }
      }
    }
  }
  {
    if (false)
      cerr << '#' << 1088 << '\n'
           << "  black: " << (black) << '\n'
           << "  costs: " << (costs) << '\n';
  }
  for (bool b : black) cout << (b ? 'B' : 'W');
  cout << '\n';
  for (LL Rb_ = (M), j = (0); j < Rb_; ++(j))
    cout << costs[make_pair(U[j], V[j])] << '\n';
}
