#include <bits/stdc++.h>
using namespace std;
inline int qr() {
  int ret = 0, f = 0, c = getchar();
  while (!isdigit(c)) f |= c == 45, c = getchar();
  while (isdigit(c)) ret = ret * 10 + c - 48, c = getchar();
  return f ? -ret : ret;
}
const int maxn = 1e5 + 5;
const int inf = 1e9;
struct E {
  int to, nx;
} e[maxn << 2];
int head[maxn], ans[maxn << 1], usd[maxn], n, m, cnt, D[maxn];
char col[maxn];
void add(int fr, int to) {
  static int cnt = 1;
  e[++cnt] = (E){to, head[fr]};
  head[fr] = cnt;
  e[++cnt] = (E){fr, head[to]};
  head[to] = cnt;
}
priority_queue<pair<int, int> > q;
int main() {
  n = qr();
  m = qr();
  for (int t = 1; t <= n; ++t) D[t] = qr();
  for (int t = 1, a, b; t <= m; ++t) {
    a = qr(), b = qr(), add(a, b);
    if (D[a] == D[b] && !col[a] && !col[b])
      q.emplace(D[a], a), q.emplace(D[b], b), col[a] = 'W', col[b] = 'B',
                                              ans[t] = D[a];
  }
  while (q.size()) {
    int now = q.top().second;
    q.pop();
    for (int t = head[now]; t; t = e[t].nx)
      if (!col[e[t].to] && D[e[t].to] >= D[now])
        col[e[t].to] = "WB"[col[now] == 'W'], ans[t >> 1] = D[e[t].to],
        q.emplace(D[e[t].to], e[t].to);
  }
  for (int t = 1; t <= n; ++t)
    if (col[t] == 0) return puts("-1"), 0;
  puts(col + 1);
  for (int t = 1; t <= m; ++t) printf("%d\n", ans[t] ? ans[t] : inf);
  return 0;
}
