#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
constexpr long long INF = 1000000000000000000;
constexpr long long mod = 1000000007;
constexpr double eps = 1e-8;
const double pi = acos(-1);
long long dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
long long Random(long long mi, long long ma) {
  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<long long> engine(mi, ma);
  return engine(mt);
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
bool prime(long long a) {
  if (a == 1) return false;
  for (long long i = 2; i * i <= a; i++) {
    if (a % i == 0) return false;
  }
  return true;
}
long long modpow(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2) return modpow(a, b - 1) * a % mod;
  long long memo = modpow(a, b / 2);
  return memo * memo % mod;
}
vector<long long> kaijo, invkaijo;
void init_fact(long long n) {
  kaijo.resize(n + 1);
  invkaijo.resize(n + 1);
  kaijo[0] = 1;
  for (long long i = 1; i <= n; i++) {
    kaijo[i] = kaijo[i - 1] * i;
    kaijo[i] %= mod;
  }
  for (long long i = 0; i < n + 1; i++) invkaijo[i] = modpow(kaijo[i], mod - 2);
}
long long comb(long long a, long long b) {
  if (a < b) return 0;
  if (a < 0 || b < 0) return 0;
  return kaijo[a] * invkaijo[a - b] % mod * invkaijo[b] % mod;
}
long long inv(long long x) {
  x = modpow(x, mod - 2);
  return x;
}
vector<long long> G[100010];
long long color[100010];
vector<long long> H[100010];
void dfs(long long x) {
  for (long long i : H[x]) {
    if (color[i] == -1) {
      color[i] = 1 - color[x];
      dfs(i);
    }
  }
}
void solve() {
  long long n, m, d[100010], p[100010], a[200010], b[200010];
  map<pair<long long, long long>, long long> mp;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> d[i];
    color[i] = -1;
  }
  for (long long i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
  }
  for (long long i = 0; i < n; i++) {
    pair<long long, long long> mi = {INF, -1};
    for (long long j : G[i]) {
      chmin(mi, pair<long long, long long>{d[j], j});
    }
    p[i] = mi.second;
    if (d[i] < mi.first) {
      puts("-1");
      return;
    }
  }
  for (long long i = 0; i < n; i++) {
    H[i].push_back(p[i]);
    H[p[i]].push_back(i);
    pair<long long, long long> c = {i, p[i]};
    if (c.first > c.second) swap(c.first, c.second);
    mp[c] = d[i];
  }
  color[0] = 0;
  dfs(0);
  for (long long i = 0; i < n; i++) cout << (color[i] ? 'W' : 'B');
  cout << endl;
  for (long long i = 0; i < m; i++) {
    pair<long long, long long> c = {a[i], b[i]};
    if (c.first > c.second) swap(c.first, c.second);
    if (mp.find(c) != mp.end())
      cout << mp[c] << endl;
    else
      cout << 1000000000 << endl;
  }
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
