#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long nm = 0;
  bool fh = true;
  char cw = getchar();
  for (; !isdigit(cw); cw = getchar()) fh ^= (cw == '-');
  for (; isdigit(cw); cw = getchar()) nm = nm * 10 + (cw - '0');
  return fh ? nm : -nm;
}
namespace CALC {
inline int add(int x, int y) {
  return (x + y >= 998244353) ? (x + y - 998244353) : (x + y);
}
inline int mns(int x, int y) {
  return (x - y < 0) ? (x - y + 998244353) : (x - y);
}
inline int mul(int x, int y) { return (long long)x * (long long)y % 998244353; }
inline void upd(int &x, int y) {
  x += y;
  (x >= 998244353) ? (x -= 998244353) : 0;
}
inline void dec(int &x, int y) {
  x -= y;
  (x < 0) ? (x += 998244353) : 0;
}
inline int qpow(int x, int sq) {
  int res = 1;
  for (; sq; sq >>= 1, x = mul(x, x))
    if (sq & 1) res = mul(res, x);
  return res;
}
}  // namespace CALC
using namespace CALC;
int n, m, u[400200], v[400200], D[400200], fs[400200], nt[400200], to[400200],
    od[400200], fa[400200], tmp;
inline bool cmp(int x, int y) { return D[x] < D[y]; }
inline void link(int x, int y) { nt[tmp] = fs[x], fs[x] = tmp, to[tmp++] = y; }
int main() {
  n = read(), m = read(), memset(fs, -1, sizeof(fs));
  int mi = 0, dn = 1000000000 + 1;
  for (int i = 1; i <= n; i++) D[i] = read(), od[i] = i, dn = min(dn, D[i]);
  for (int i = 1; i <= m; i++) {
    u[i] = read(), v[i] = read(), link(u[i], v[i]), link(v[i], u[i]);
    if (D[u[i]] == dn && D[v[i]] == dn) mi = u[i];
  }
  if (mi == 0) {
    puts("-1");
    return 0;
  }
  D[mi] = 0, sort(od + 1, od + n + 1, cmp);
  for (int i = 2; i <= n; i++) {
    int x = od[i];
    for (int i = fs[x]; i != -1; i = nt[i])
      if (D[to[i]] < D[x]) fa[x] = to[i];
    if (!fa[x]) {
      puts("-1");
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) putchar((i == mi) ? 'B' : 'W');
  puts("");
  for (int i = 1; i <= m; i++) {
    int x = u[i], y = v[i];
    if (fa[y] == x) swap(x, y);
    if (fa[x] == y)
      printf("%d\n", D[x] - D[y]);
    else
      printf("%d\n", 1000000000);
  }
  return 0;
}
