#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int x = 0, f = 1;
  register char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = 0;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch ^ '0');
    ch = getchar();
  }
  return f ? x : -x;
}
const int N = 1e5 + 5, inf = 0x7fffffff;
const char ch[] = "BW";
int n, m, d[N], num = 1, head[N], w[N << 1], col[N], fa[N];
struct edge {
  int to, next, vis;
} e[N << 2];
inline void add(int u, int v) {
  e[++num] = (edge){v, head[u]}, head[u] = num;
  e[++num] = (edge){u, head[v]}, head[v] = num;
}
inline void dfs(int u) {
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (!e[i].vis || ~col[v]) continue;
    col[v] = 1 - col[u];
    dfs(v);
  }
}
int main() {
  n = read(), m = read();
  for (int i = (1), _ed = (n); i <= _ed; ++i) d[i] = read();
  for (int i = (1), _ed = (m); i <= _ed; ++i) add(read(), read()), w[i] = inf;
  for (int u = (1), _ed = (n); u <= _ed; ++u) {
    if (!head[u]) return puts("-1"), 0;
    ;
    int p = head[u];
    for (int i = e[p].next; i; i = e[i].next) {
      if (d[e[i].to] < d[e[p].to])
        p = i;
      else if (d[e[i].to] == d[e[p].to] && e[i].to < e[p].to)
        p = i;
    }
    if (d[e[p].to] > d[u]) return puts("-1"), 0;
    ;
    e[p ^ 1].vis = 1;
    w[p >> 1] = d[u];
    fa[u] = e[p].to;
  }
  memset(col, -1, sizeof col);
  for (int i = (1), _ed = (n); i <= _ed; ++i)
    if (fa[fa[i]] == i && !~col[i]) col[i] = 0, dfs(i);
  for (int i = (1), _ed = (n); i <= _ed; ++i) putchar(ch[col[i]]);
  puts("");
  for (int i = (1), _ed = (m); i <= _ed; ++i) printf("%d\n", w[i]);
  return 0;
}
