#include <bits/stdc++.h>
using namespace std;
const int maxn = 110000;
const int maxm = 210000;
const int inf = 1e9 + 7;
struct edge {
  int to, nxt;
} e[maxm];
int h[maxn], E;
int n, m;
int d[maxn];
int u[maxm], v[maxm], w[maxm];
int use[maxn];
int col[maxn];
void add(int u, int v) {
  E++;
  e[E].to = v;
  e[E].nxt = h[u];
  h[u] = E;
  return;
}
void dfs(int u, int fa) {
  col[u] = col[fa] ^ 1;
  for (int i = h[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa) continue;
    dfs(v, u);
  }
  return;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u[i], &v[i]);
    if (d[u[i]] < d[v[i]]) {
      if (use[v[i]]) continue;
      use[v[i]] = 1;
      w[i] = d[v[i]];
      add(u[i], v[i]);
      add(v[i], u[i]);
    } else if (d[u[i]] > d[v[i]]) {
      if (use[u[i]]) continue;
      use[u[i]] = 1;
      w[i] = d[u[i]];
      add(u[i], v[i]);
      add(v[i], u[i]);
    } else {
      if (use[u[i]] && use[v[i]]) continue;
      if (use[i] == 0 && use[v[i]] == 0)
        use[u[i]] = 2, use[v[i]] = 1;
      else {
        if (use[u[i]] == 0) use[u[i]] = 1;
        if (use[v[i]] == 0) use[v[i]] = 1;
      }
      w[i] = max(d[u[i]], d[v[i]]);
      add(u[i], v[i]);
      add(v[i], u[i]);
    }
  }
  int fag = 0;
  for (int i = 1; i <= n; i++) {
    if (!use[i]) fag = 1;
    if (use[i] == 2) dfs(i, 0);
  }
  if (fag) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (col[i])
      printf("W");
    else
      printf("B");
  }
  printf("\n");
  for (int i = 1; i <= m; i++) {
    if (w[i] == 0)
      printf("1000000000\n");
    else
      printf("%d\n", w[i]);
  }
  return 0;
}
