#include <bits/stdc++.h>
using namespace std;
int D[800050];
struct graph {
  struct point {
    int next, to;
  } ar[800050];
  int head[800050], art = 1;
  inline void link(int u, int v) {
    ar[++art] = {head[u], v}, head[u] = art;
    ar[++art] = {head[v], u}, head[v] = art;
  }
} G, G1;
int ans[800050], a[800050];
inline void read(int&), dfs(int, bool);
int main() {
  freopen("in", "r", stdin);
  int N, M;
  read(N), read(M);
  for (int i(1); i <= N; ++i) read(D[i]);
  for (int i(1), u, v; i <= M; ++i)
    read(u), read(v), G.link(u, v), ans[i] = 1e9;
  for (int i(1), j, i1; i <= N; ++i) {
    for (j = G.head[i], i1 = 0; j; j = G.ar[j].next)
      if (!i1 || make_pair(D[G.ar[j].to], G.ar[j].to) <
                     make_pair(D[G.ar[i1].to], G.ar[i1].to))
        i1 = j;
    if (D[G.ar[i1].to] > D[i]) return puts("-1"), 0;
    ans[i1 >> 1] = D[i], G1.link(i, G.ar[i1].to);
  }
  memset(a, -1, sizeof(a)), dfs(1, 0);
  for (int i(1); i <= N; ++i) putchar(a[i] ? 'B' : 'W');
  putchar('\n');
  for (int i(1); i <= M; ++i) printf("%d\n", ans[i]);
  return 0;
}
inline void dfs(int x, bool c) {
  a[x] = c;
  for (int i(G1.head[x]), i1; i; i = G1.ar[i].next)
    if (!~a[i1 = G1.ar[i].to]) dfs(i1, c ^ 1);
}
inline void read(int& x) {
  x ^= x;
  register char c;
  while (c = getchar(), c < '0' || c > '9')
    ;
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
