#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int x = 0, f = 1;
  register char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
  return x * f;
}
inline int Mul(int a, int b) { return 1ll * a * b % 1000000007; }
inline int Inc(int a, int b) {
  return (a += b) >= 1000000007 ? a - 1000000007 : a;
}
inline int Dec(int a, int b) { return (a -= b) < 0 ? a + 1000000007 : a; }
inline int qpow(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1) r = Mul(r, a);
    a = Mul(a, a), b >>= 1;
  }
  return r;
}
int n, m, head[100005], cnt = 1, d[100005], v[100005], vis[100005], col[100005],
                        b[100005];
struct edge {
  int id, v, w, next;
} e[100005 << 2];
struct node {
  int a, b;
} a[100005];
inline bool cmp1(node a, node b) { return a.b < b.b; }
inline void add(int id, int u, int v) {
  e[++cnt] = (edge){id, v, -1, head[u]}, head[u] = cnt;
  e[++cnt] = (edge){id, u, -1, head[v]}, head[v] = cnt;
}
inline bool cmp(edge a, edge b) { return a.id < b.id; }
inline void dfs(int u, int f) {
  col[u] = f, vis[u] = 1;
  for (register int i = head[u]; i; i = e[i].next) {
    if (vis[e[i].v]) {
      if (e[i].w == -1) e[i].w = e[i ^ 1].w = 1000000000;
      continue;
    }
    if (e[i].w != -1 && e[i].w != 1000000000)
      dfs(e[i].v, f ^ 1);
    else
      e[i].w = e[i ^ 1].w = 1000000000;
  }
}
int main() {
  n = read(), m = read();
  for (int i = (1), iLimit = (n); i <= iLimit; ++i)
    a[i].a = i, b[i] = a[i].b = read();
  sort(a + 1, a + n + 1, cmp1);
  for (int i = (1), iLimit = (m); i <= iLimit; ++i) {
    int u = read(), v = read();
    add(i, u, v);
  }
  for (int j = (1), jLimit = (n); j <= jLimit; ++j) {
    if (vis[a[j].a]) {
      for (register int i = head[a[j].a]; i; i = e[i].next)
        e[i].w = e[i ^ 1].w = max(b[e[i].v], a[j].b), vis[e[i].v] = 1;
      continue;
    }
    int flag = 0;
    for (register int i = head[a[j].a]; i; i = e[i].next)
      if (a[j].b == b[e[i].v]) {
        e[i].w = e[i ^ 1].w = a[j].b, vis[a[j].a] = flag = vis[e[i].v] = 1;
      }
    if (!flag) return puts("-1"), 0;
  }
  memset(vis, 0, sizeof(vis)), dfs(1, 0);
  for (int i = (1), iLimit = (n); i <= iLimit; ++i)
    if (col[i])
      putchar('B');
    else
      putchar('W');
  puts("");
  sort(e + 2, e + cnt + 1, cmp);
  for (register int i = 2; i <= cnt; i += 2) printf("%d\n", e[i].w);
  return 0;
}
