#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int stack[20];
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (!x) {
    putchar('0');
    return;
  }
  int top = 0;
  while (x) stack[++top] = x % 10, x /= 10;
  while (top) putchar(stack[top--] + '0');
}
template <typename T>
inline void pr1(T x) {
  write(x);
  putchar(' ');
}
template <typename T>
inline void pr2(T x) {
  write(x);
  putchar('\n');
}
const int MAXN = 100005;
const int MAXM = 200005;
struct edge {
  int x, y, next;
} a[2 * MAXM];
int len = 1, last[MAXN];
bool flag[MAXM];
void ins(int x, int y) {
  len++;
  a[len].x = x;
  a[len].y = y;
  a[len].next = last[x];
  last[x] = len;
}
int n, m, D[MAXN], id[MAXN], val[MAXM];
bool cmp(int n1, int n2) { return D[n1] < D[n2]; }
void mark(int k, int u) {
  flag[k] = flag[k ^ 1] = 1;
  val[k] = val[k ^ 1] = u;
}
int flag1[MAXN], ok[MAXN];
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) D[i] = read(), id[i] = i;
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read();
    ins(u, v);
    ins(v, u);
  }
  sort(id + 1, id + 1 + n, cmp);
  int kk = -1;
  for (int i = 1; i <= n; i++)
    if (D[id[i]] == D[id[1]]) {
      for (int k = last[id[i]]; k; k = a[k].next) {
        int y = a[k].y;
        if (D[y] == D[1]) {
          kk = k;
          break;
        }
      }
    }
  if (kk == -1) return pr2(-1), 0;
  mark(kk, D[id[1]]);
  ok[a[kk].x] = ok[a[kk].y] = 1;
  flag1[a[kk].y] = 1;
  for (int i = 1; i <= n; i++)
    if (!ok[id[i]]) {
      bool tf = false;
      int x = id[i];
      for (int k = last[x]; k; k = a[k].next)
        if (D[a[k].y] <= D[x]) {
          tf = true;
          ok[x] = 1;
          if (D[a[k].y] < D[x])
            flag1[x] = flag1[a[k].y], mark(k, D[x] - D[a[k].y]);
          else {
            if (ok[a[k].y])
              flag1[x] = flag1[a[k].y] ^ 1, mark(k, D[x]);
            else
              ok[a[k].y] = 1, flag1[x] = 1, mark(k, D[x]);
          }
          break;
        }
      if (!tf) return pr2(-1), 0;
    }
  for (int i = 1; i <= n; i++) putchar(flag1[i] ? 'B' : 'W');
  puts("");
  for (int i = 2; i < len; i += 2) {
    if (flag[i])
      pr2(val[i]);
    else
      pr2(1000000000);
  }
  return 0;
}
