#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const long long INF = 1LL << 60;
const long long mod = 1e9 + 7;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
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;
}
long long n, m;
vector<long long> d;
vector<vector<long long>> g;
void solve() {
  cin >> n >> m;
  d.resize(n);
  vector<pair<long long, long long>> p(n);
  for (long long i = 0; i < n; i++) {
    cin >> d[i];
    p[i] = {d[i], i};
  }
  sort(p.begin(), p.end());
  g.assign(n, vector<long long>());
  map<pair<long long, long long>, long long> mp;
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
    mp[{u, v}] = i;
    mp[{v, u}] = i;
  }
  vector<long long> c(m, 1e9);
  vector<long long> s(n, -1);
  for (long long i = 0; i < n; i++) {
    bool ok = 0;
    long long v = p[i].second;
    if (s[v] != -1) continue;
    for (long long nv : g[v]) {
      if (d[v] == d[nv]) {
        if (s[nv] == -1) {
          s[nv] = 1, s[v] = 0;
          c[mp[{v, nv}]] = d[v];
        } else {
          s[nv] = 1 - s[v];
          c[mp[{v, nv}]] = d[v];
        }
        ok = 1;
        continue;
      } else if (d[v] > d[nv]) {
        s[v] = s[nv];
        c[mp[{v, nv}]] = d[v] - d[nv];
        ok = 1;
        continue;
      }
    }
    if (!ok) {
      cout << -1 << endl;
      return;
    }
  }
  for (long long i = 0; i < n; i++) {
    cout << (s[i] == 0 ? 'B' : 'W');
  }
  cout << endl;
  for (long long i = 0; i < m; i++) {
    cout << c[i] << endl;
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
