#include <bits/stdc++.h>
using namespace std;
template <typename T>
void cetak(T t) {
  cout << t << ')' << endl;
}
template <typename T, typename... V>
void cetak(T t, V... v) {
  cout << t;
  if (sizeof...(v)) cout << ", ";
  cetak(v...);
}
const int MOD = 1e9 + 7;
int add(int x, int y) {
  int ret = x + y;
  if (ret >= MOD) ret -= MOD;
  return ret;
}
int sub(int x, int y) {
  int ret = x - y;
  if (ret < 0) ret += MOD;
  return ret;
}
int mul(int x, int y) { return (long long)x * y % MOD; }
const int mx = 1e5 + 10;
int find(vector<int> &par, int x) {
  if (par[x] == x) return x;
  return par[x] = find(par, par[x]);
}
void gabung(vector<int> &par, int i, int j) {
  i = find(par, i);
  j = find(par, j);
  if (i != j) par[i] = j;
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  vector<int> d(n), w(m, 1e9), u(m), v(m), par(n * 2, 0), ve(m), c(n, -1);
  iota(ve.begin(), ve.end(), 0);
  iota(par.begin(), par.end(), 0);
  for (int i = 0; i < n; i++) cin >> d[i];
  map<pair<int, int>, int> apa;
  for (int i = 0; i < m; i++) {
    cin >> u[i] >> v[i];
    u[i] -= 1;
    v[i] -= 1;
    apa[{u[i], v[i]}] = apa[{v[i], u[i]}] = i;
    g[u[i]].push_back(v[i]);
    g[v[i]].push_back(u[i]);
  }
  sort(ve.begin(), ve.end(), [&](int i, int j) {
    int x = abs(d[u[i]] - d[v[i]]);
    int y = abs(d[u[j]] - d[v[j]]);
    if (x == y) return d[u[i]] < d[u[j]];
    return x < y;
  });
  set<int> aa;
  for (int i : ve) {
    if (d[u[i]] == d[v[i]]) {
      if (aa.count(u[i]) && aa.count(v[i])) continue;
      aa.insert(u[i]);
      aa.insert(v[i]);
      if (c[u[i]] == -1 && c[v[i]] == -1) {
        c[u[i]] = 0;
        c[v[i]] = 1;
      } else if (c[u[i]] == -1)
        c[u[i]] = c[v[i]] ^ 1;
      else
        c[v[i]] = c[u[i]] ^ 1;
      w[i] = d[u[i]];
    }
  }
  queue<int> q;
  for (int i : aa) q.push(i);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i : g[now]) {
      if (aa.count(i)) continue;
      if (d[i] > d[now]) {
        aa.insert(i);
        q.push(i);
        w[apa[{now, i}]] = d[i] - d[now];
        c[i] = c[now] ^ 1;
      }
    }
  }
  if ((int)(aa.size()) < n) {
    cout << -1 << endl;
    return;
  }
  for (int i = 0; i < n; i++) {
    int j = i + n;
    int x = find(par, i);
    int y = find(par, j);
    if (x == y) {
      cout << -1 << endl;
      return;
    }
  }
  for (int i = 0; i < n; i++) {
    if (c[i])
      cout << 'B';
    else
      cout << 'W';
  }
  cout << endl;
  for (int i = 0; i < m; i++) cout << w[i] << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
