#include <bits/stdc++.h>
using namespace std;
char *fs, *ft, buf[1 << 15];
inline char getc() {
  return (fs == ft &&
          (ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), fs == ft))
             ? 0
             : *fs++;
}
inline int read() {
  int x = 0, f = 1;
  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;
}
const int MAXN = 100010;
int n, len = 1, m, flag;
int a[MAXN], vis[MAXN];
int lin[MAXN], ver[MAXN << 1], nex[MAXN << 1], e[MAXN << 1];
priority_queue<pair<int, int> > q;
inline void add(int x, int y) {
  ver[++len] = y;
  nex[len] = lin[x];
  lin[x] = len;
}
inline void dij() {
  a[0] = 1000000000;
  memset(vis, -1, sizeof(vis));
  while (q.size()) {
    int x = q.top().second;
    q.pop();
    if (vis[x] != -1) continue;
    vis[x] = 1;
    int minn = 0, op, p;
    for (int i = lin[x]; i; i = nex[i]) {
      int tn = ver[i];
      if (a[tn] < a[minn]) {
        minn = tn;
        p = i;
        op = vis[tn];
      }
    }
    if (a[minn] > a[x]) {
      flag = 1;
      return;
    }
    if (op == -1) {
      vis[minn] = vis[x] ^ 1;
      e[p] = e[p ^ 1] = a[x];
    } else {
      vis[x] = vis[minn] ^ 1;
      e[p] = e[p ^ 1] = a[x];
    }
  }
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; ++i) {
    a[i] = read();
    q.push(make_pair(-a[i], i));
  }
  for (int i = 1; i <= m; ++i) {
    int x, y;
    x = read();
    y = read();
    add(x, y);
    add(y, x);
  }
  dij();
  if (flag) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i <= n; ++i) printf(vis[i] ? "W" : "B");
  puts("");
  for (int i = 2; i <= len; i += 2) {
    if (e[i])
      printf("%d\n", e[i]);
    else
      printf("%d\n", 1000000000);
  }
  return 0;
}
