#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <class S, class T>
ostream &operator<<(ostream &os, pair<S, T> p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long inf = 1000000001;
const long long INF = (long long)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
long long dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
long long dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1},
          dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long MOD = 1000000007;
long long n, m;
vector<long long> d;
vector<vector<pair<long long, long long>>> G;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ;
  cin >> n >> m;
  d.resize(n);
  for (long long i = 0; i < (n); i++) cin >> d[i];
  G.resize(n);
  for (long long i = 0; i < (m); i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].push_back(pair<long long, long long>(v, i));
    G[v].push_back(pair<long long, long long>(u, i));
  }
  vector<pair<long long, long long>> du(n);
  for (long long i = 0; i < (n); i++) {
    bool flag = false;
    du[i] = pair<long long, long long>(d[i], i);
    for (pair<long long, long long> vid : G[i]) {
      long long v = vid.first;
      if (d[v] <= d[i]) {
        flag = true;
        break;
      }
    }
    if (not flag) {
      cout << -1 << endl;
      return 0;
    }
  }
  sort(du.begin(), du.end());
  string color(n, '?');
  vector<long long> ans(m, inf);
  for (long long i = 0; i < (n); i++) {
    if (color[i] != '?') continue;
    long long x = du[i].first, u = du[i].second;
    for (pair<long long, long long> vid : G[u]) {
      long long v = vid.first, idx = vid.second;
      if (d[v] > d[u]) continue;
      if (d[v] == d[u]) {
        char ai = color[v];
        char me;
        if (ai == '?') {
          ai = 'B';
          me = 'W';
        } else {
          if (ai == 'B')
            me = 'W';
          else
            me = 'B';
        }
        color[v] = ai;
        color[u] = me;
        ans[idx] = x;
        break;
      } else {
        char ai = color[v];
        char me;
        if (ai == 'B')
          me = 'W';
        else
          me = 'B';
        color[u] = me;
        ans[idx] = x;
        break;
      }
    }
  }
  for (long long i = 0; i < (m); i++) {
    if (ans[i] == inf) ans[i] = 1000000000;
  }
  cout << color << endl;
  for (long long i = 0; i < (m); i++) {
    cout << ans[i] << endl;
  }
}
