#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, d[N], u[N], v[N], w[N], i, e[N];
char c[N];
void E() {
  puts("-1");
  exit(0);
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; ++i) scanf("%d", d + i);
  memset(c + 1, -1, n);
  for (i = 1; i <= m; ++i)
    scanf("%d%d", u + i, v + i), e[i] = i, w[i] = max(d[u[i]], d[v[i]]);
  sort(e + 1, e + m + 1, [&](int x, int y) { return w[x] < w[y]; });
  for (i = 1; i <= m; ++i) {
    int x = u[e[i]], y = v[e[i]];
    if (c[x] == -1 && c[y] == -1) {
      if (d[x] != d[y]) {
        w[e[i]] = 1e9;
        continue;
      }
      c[x] = 0;
      c[y] = 1;
    } else if (c[x] == -1 || c[y] == -1) {
      if (c[x] == -1)
        c[x] = c[y] ^ 1;
      else
        c[y] = c[x] ^ 1;
    } else
      w[e[i]] = 1e9;
  }
  for (i = 1; i <= n; ++i)
    if (c[i] == -1) E();
  for (i = 1; i <= n; ++i) putchar(c[i] == 0 ? 'W' : 'B');
  puts("");
  for (i = 1; i <= m; ++i) printf("%d\n", w[i]);
}
