#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> ids(n);
  iota(ids.begin(), ids.end(), 0);
  vector<ll> d(n);
  for (int i = 0; i < n; ++i) {
    cin >> d[i];
  }
  sort(ids.begin(), ids.end(), [&](int i1, int i2) { return d[i1] < d[i2]; });
  if (d[ids[0]] != d[ids[1]]) {
    cout << -1 << "\n";
    return 0;
  }
  vector<vector<int> > g(n);
  vector<int> u(m), v(m);
  map<P, int> memo;
  for (int i = 0; i < m; ++i) {
    cin >> u[i] >> v[i];
    u[i]--;
    v[i]--;
    if (u[i] > v[i]) swap(u[i], v[i]);
    g[u[i]].push_back(v[i]);
    g[v[i]].push_back(u[i]);
  }
  vector<int> c(n, -1);
  for (int ii = 0; ii < n; ++ii) {
    int i = ids[ii];
    int nex = -1;
    for (int j : g[i]) {
      if (c[j] == -1) continue;
      c[i] = 1 - c[j];
      memo[minmax(i, j)] = d[i];
      break;
    }
    if (c[i] == -1) {
      for (int j : g[i]) {
        if (d[i] != d[j]) continue;
        c[i] = 0;
        c[j] = 1;
        memo[minmax(i, j)] = d[i];
        break;
      }
    }
    if (c[i] == -1) {
      cout << -1 << "\n";
      return 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << "BW"[c[i]];
  }
  cout << "\n";
  for (int i = 0; i < m; ++i) {
    P tar(u[i], v[i]);
    cout << (memo.find(tar) != memo.end() ? memo[tar] : 1000000000) << "\n";
  }
  return 0;
}
