#include <bits/stdc++.h>
using namespace std;
const long long MAX = 200001;
const long long MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(long long n, long long k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
signed d[100000], c[100000], oya[100000], ans[200000], ban[100000], n, m;
char iro[100000];
char find(signed ue, signed i) {
  if (iro[i] != 'a') return iro[i];
  if (oya[i] == ue) return iro[i] = 'W';
  if (d[i] < d[oya[i]]) return iro[i] = 'F';
  if (d[i] == d[oya[i]]) {
    ans[ban[i]] = d[i];
    switch (find(i, oya[i])) {
      case 'W':
        return iro[i] = 'B';
      case 'B':
        return iro[i] = 'W';
      case 'F':
        return iro[i] = 'F';
    }
  }
  ans[ban[i]] = d[i] - d[oya[i]];
  return iro[i] = find(i, oya[i]);
}
signed main() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> d[i];
  fill(c, c + n, 1000000001);
  fill(ans, ans + m, 1000000001);
  long long u, v;
  for (long long i = 0; i < m; i++) {
    cin >> u >> v;
    u--;
    v--;
    if (c[u] >= d[v]) {
      c[u] = d[v];
      oya[u] = v;
      ban[u] = i;
    }
    if (c[v] >= d[u]) {
      c[v] = d[u];
      oya[v] = u;
      ban[v] = i;
    }
  }
  fill(iro, iro + n, 'a');
  for (long long i = 0; i < n; i++) {
    if (find(-1, i) == 'F') {
      cout << -1;
      return 0;
    }
  }
  for (long long i = 0; i < n; i++) cout << iro[i];
  cout << endl;
  for (long long i = 0; i < m; i++) cout << ans[i] << endl;
}
