#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;
template <typename T>
using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T>
using que = queue<T>;
template <typename T>
using deq = deque<T>;
template <typename T>
T id(T b) {
  return b;
};
template <typename T>
void chmax(T &x, T y) {
  if (x < y) x = y;
}
template <typename T>
void chmin(T &x, T y) {
  if (x > y) x = y;
}
template <typename S, typename K>
bool contains(S &s, K k) {
  return s.find(k) != s.end();
}
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
}
constexpr ll TEN(int n) {
  if (n == 0)
    return 1LL;
  else
    return 10LL * TEN(n - 1);
}
const int MAX_N = 100000;
int n, m;
int d[MAX_N];
vec<pii> g[MAX_N];
void dfs(int u, int p, int c, vi &col, vec<vi> &g) {
  col[u] = c;
  for (int v : g[u]) {
    if (v == p) continue;
    dfs(v, u, 1 - c, col, g);
  }
}
int main() {
  fastio();
  cin >> n >> m;
  for (size_t i = 0; i < size_t(n); i++) cin >> d[i];
  for (size_t i = 0; i < size_t(m); i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].emplace_back(v, i);
    g[v].emplace_back(u, i);
  }
  bool ok = true;
  vec<pii> p(n);
  for (size_t i = 0; i < size_t(n); i++) {
    bool temp = false;
    int cur = INT_MAX;
    for (auto e : g[i]) {
      int v, j;
      tie(v, j) = e;
      temp |= d[i] >= d[v];
      if (cur > d[v] || (cur == d[v] && p[i].first > v)) {
        p[i] = e;
        cur = d[v];
      }
    }
    ok &= temp;
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }
  vi col(n);
  vi ans(m, TEN(9));
  vec<vi> g2(n);
  for (size_t i = 0; i < size_t(n); i++) {
    ans[p[i].second] = d[i];
    g2[i].push_back(p[i].first);
    g2[p[i].first].push_back(i);
  }
  for (size_t i = 0; i < size_t(n); i++) {
    dfs(i, -1, 0, col, g2);
  }
  for (size_t i = 0; i < size_t(n); i++) {
    cout << (col[i] ? 'B' : 'W');
  }
  cout << endl;
  for (size_t i = 0; i < size_t(m); i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
