#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long to;
  long long cost, num;
  edge() {}
  edge(long long to, long long cost, long long num)
      : to(to), cost(cost), num(num){};
};
int main() {
  long long n, m;
  cin >> n >> m;
  vector<vector<edge>> g(n);
  vector<vector<edge>> gg(n);
  vector<long long> v(n);
  for (long long i = 0; i < (long long)(n); i++) {
    cin >> v[i];
  }
  for (long long i = 0; i < (long long)(m); i++) {
    long long a, b;
    cin >> a >> b;
    g[a - 1].emplace_back(b - 1, -1, i);
    g[b - 1].emplace_back(a - 1, -1, i);
  }
  for (long long i = 0; i < (long long)(n); i++) {
    bool ok = 0;
    for (auto r : g[i])
      if (v[i] >= v[r.to]) ok = 1;
    if (!ok) {
      cout << -1 << endl;
      return 0;
    }
  }
  vector<bool> s(n, 0);
  vector<bool> see(n, 0);
  vector<long long> ans(n, 1000000000);
  for (long long i = 0; i < (long long)(n); i++) {
    if (see[i]) continue;
    long long mi = 1LL << 40;
    for (auto r : g[i]) mi = min(mi, v[r.to]);
    for (auto r : g[i])
      if (mi == v[r.to]) {
        ans[r.num] = v[i];
        gg[r.to].emplace_back(i, -1, i);
        gg[i].emplace_back(r.to, -1, i);
        break;
      }
  }
  for (long long i = 0; i < (long long)(n); i++) {
    if (see[i]) continue;
    queue<long long> q;
    q.push(i);
    while (!q.empty()) {
      long long p = q.front();
      see[p] = 1;
      q.pop();
      for (auto r : gg[p]) {
        if (!see[r.to]) {
          s[r.to] = !s[p];
          q.push(r.to);
        }
      }
    }
  }
  string ss = "";
  for (long long i = 0; i < (long long)(n); i++) {
    if (s[i])
      ss += 'B';
    else
      ss += 'W';
  }
  cout << ss << endl;
  for (auto r : ans) cout << r << endl;
  return 0;
}
