#include <bits/stdc++.h>
clock_t t = clock();
namespace my_std {
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
inline T rnd(T l, T r) {
  return uniform_int_distribution<T>(l, r)(rng);
}
template <typename T>
inline bool chkmax(T& x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmin(T& x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
inline void read(T& t) {
  t = 0;
  char f = 0, ch = getchar();
  double d = 0.1;
  while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
  while (ch <= '9' && ch >= '0') t = t * 10 + ch - 48, ch = getchar();
  if (ch == '.') {
    ch = getchar();
    while (ch <= '9' && ch >= '0') t += d * (ch ^ 48), d *= 0.1, ch = getchar();
  }
  t = (f ? -t : t);
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
char __sr[1 << 21], __z[20];
int __C = -1, __zz = 0;
inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; }
inline void print(register int x) {
  if (__C > 1 << 20) Ot();
  if (x < 0) __sr[++__C] = '-', x = -x;
  while (__z[++__zz] = x % 10 + 48, x /= 10)
    ;
  while (__sr[++__C] = __z[__zz], --__zz)
    ;
  __sr[++__C] = '\n';
}
void file() {}
inline void chktime() {}
long long ksm(long long x, int y) {
  long long ret = 1;
  for (; y; y >>= 1, x = x * x)
    if (y & 1) ret = ret * x;
  return ret;
}
}  // namespace my_std
using namespace my_std;
int n, m;
struct hh {
  int t, nxt;
} edge[401010 << 1];
int head[401010], ecnt = 1;
void make_edge(int f, int t) {
  edge[++ecnt] = (hh){t, head[f]};
  head[f] = ecnt;
  edge[++ecnt] = (hh){f, head[t]};
  head[t] = ecnt;
}
int d[401010];
int ans[401010], W[401010];
vector<int> V, VV;
int fa[401010], vis[401010], in[401010];
int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]); }
void solve() {
  if (V.size() == 1u) return;
  int mn = 1e9, n = (int)V.size() - 1;
  for (int i = (1); i <= (n); i++) chkmin(mn, d[V[i]]);
  for (int i = (1); i <= (n); i++) fa[V[i]] = V[i];
  for (int x = (1); x <= (n); x++)
    for (int i = head[V[x]]; i; i = edge[i].nxt)
      if (d[V[x]] == mn && d[edge[i].t] == mn)
        fa[getfa(V[x])] = getfa(edge[i].t), vis[getfa(edge[i].t)] = 1;
  for (int i = (1); i <= (n); i++)
    if (d[V[i]] == mn && V[i] == fa[V[i]] && !vis[V[i]]) exit(puts("-1") & 0);
  queue<int> q;
  for (int i = (1); i <= (n); i++)
    if (d[V[i]] == mn)
      ans[V[i]] = (V[i] == fa[V[i]]), q.push(V[i]), vis[V[i]] = 0, in[V[i]] = 1;
  for (int x = (1); x <= (n); x++)
    if (d[V[x]] == mn) {
      int flg = 1;
      for (int i = head[V[x]]; i; i = edge[i].nxt)
        if (d[edge[i].t] == mn && ans[edge[i].t] != ans[V[x]]) flg = 0;
      ans[V[x]] ^= flg;
    }
  for (int x = (1); x <= (n); x++)
    for (int i = head[V[x]]; i; i = edge[i].nxt)
      if (d[V[x]] == mn && d[edge[i].t] == mn)
        vis[i >> 1] = 1, W[i >> 1] = (ans[V[x]] == ans[edge[i].t] ? 1e9 : mn);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = head[x]; i; i = edge[i].nxt)
      if (vis[i >> 1])
        ;
      else if (in[edge[i].t] || d[edge[i].t] < d[x])
        W[i >> 1] = 1e9, vis[i >> 1] = 1;
      else
        ans[edge[i].t] = ans[x] ^ 1, W[i >> 1] = d[edge[i].t],
        q.push(edge[i].t), in[edge[i].t] = 1, vis[i >> 1] = 1;
  }
  VV.clear();
  for (int i = (0); i <= (n); i++)
    if (!in[V[i]]) VV.push_back(V[i]);
  V = VV;
  solve();
}
int main() {
  file();
  read(n, m);
  for (int i = (1); i <= (n); i++) read(d[i]);
  int x, y;
  for (int i = (1); i <= (m); i++) read(x, y), make_edge(x, y);
  for (int i = (0); i <= (n); i++) V.push_back(i);
  solve();
  for (int i = (1); i <= (n); i++)
    if (!in[i]) return puts("-1"), 0;
  for (int i = (1); i <= (n); i++) putchar("BW"[ans[i]]);
  puts("");
  for (int i = (1); i <= (m); i++) printf("%d\n", W[i]);
  return 0;
}
