#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
using namespace std;
template <class t>
inline t read(t &x) {
  char c = getchar();
  bool f = 0;
  x = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f) x = -x;
  return x;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t>
inline void write(t x) {
  if (x < 0)
    putchar('-'), write(-x);
  else {
    if (x > 9) write(x / 10);
    putchar('0' + x % 10);
  }
}
const int N = 2e5 + 5;
vector<pair<int, int> > g[N];
int col[N], a[N], p[N], ans[N], m, n;
void color(int x) {
  if (col[x]) return;
  for (auto [y, i] : g[x])
    if (!col[y] && a[x] == a[y]) {
      col[x] = 1;
      col[y] = 2;
      ans[i] = a[x];
      return;
    }
  for (auto [y, i] : g[x])
    if (col[y]) {
      col[x] = 3 - col[y];
      ans[i] = 1e9;
      return;
    }
  write(-1);
  exit(0);
}
signed main() {
  read(n, m);
  for (int i = 1; i <= n; i++) read(a[i]), p[i] = i;
  for (int i = 1, x, y; i <= m; i++) {
    read(x, y);
    g[x].emplace_back(y, i);
    g[y].emplace_back(x, i);
  }
  sort(p + 1, p + 1 + n,
       [](const int &x, const int &y) { return a[x] < a[y]; });
  for (int i = 1; i <= n; i++) color(p[i]);
  for (int i = 1; i <= n; i++) putchar(col[i] == 1 ? 'B' : 'W');
  puts("");
  for (int i = 1; i <= m; i++) write(ans[i] ? ans[i] : 1000000000), puts("");
}
