#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chkmin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
inline void chkmax(T &a, T b) {
  if (a < b) a = b;
}
inline int read() {
  int s = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') ch = getchar(), f = -1;
  while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar();
  return ~f ? s : -s;
}
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 20;
struct Edge {
  int u, v, w;
};
Edge E[maxn];
int d[maxn], n, m, vis[maxn], col[maxn];
vector<int> ed[maxn];
queue<int> q;
inline void init() {
  n = read();
  m = read();
  for (int i = (1), _end_ = (n); i <= _end_; i++) d[i] = read();
  for (int i = (1), _end_ = (m); i <= _end_; i++) {
    int u = read(), v = read();
    E[i] = (Edge){u, v, inf};
    if (d[u] == d[v] && !vis[u] && !vis[v])
      q.push(u), q.push(v), E[i].w = d[u], vis[u] = 1, vis[v] = 1, col[u] = 1,
                            col[v] = 0;
    ed[u].push_back(i);
    ed[v].push_back(i);
  }
}
inline void doing() {
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i : ed[u]) {
      int v = E[i].u ^ E[i].v ^ u;
      if (d[v] >= d[u] && !vis[v])
        vis[v] = 1, q.push(v), E[i].w = d[v], col[v] = col[u] ^ 1;
    }
  }
  int s = 0;
  for (int i = (1), _end_ = (n); i <= _end_; i++) s += vis[i];
  if (s == n) {
    for (int i = (1), _end_ = (n); i <= _end_; i++)
      printf("%c", col[i] ? 'B' : 'W');
    puts("");
    for (int i = (1), _end_ = (m); i <= _end_; i++) printf("%d\n", E[i].w);
  } else
    puts("-1");
}
int main() {
  init();
  doing();
  return 0;
}
