#include <bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair <int, int>
#define iiii pair <int, pii >
#define mp make_pair
#define INF 1000000000
#define rep(i, x) for(int (i) = 0; (i) < (x); (i)++)
inline int getint() {
  int x = 0, p = 1; char c = getchar();
  while (c <= 32) c = getchar();
  if (c == 45) p = -p, c = getchar();
  while (c > 32) x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
const int mod = 1e9 + 7;
inline void reduce(int &x) { x += x >> 31 & mod; }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
//ruogu_alter
const int N = 2e5 + 5;
int n, m, len[N], vis[N], d[N];
vector<pii> v, g[N];
//
int main() {
  n = getint(); m = getint();
  rep(i, n) v.emplace_back(d[i] = getint(), i);
  sort(v.begin(), v.end());
  rep(i, m) {
    int x = getint() - 1, y = getint() - 1;
    g[x].emplace_back(y, i);
    g[y].emplace_back(x, i);
  }
  rep(i, m) len[i] = INF;
  for (auto &u : v) {
    int s = u.second, l = u.first;
    if (vis[s]) continue;
    bool fg = false;
    for (auto &to : g[s]) if (vis[to.first]) {
      fg = true;
      vis[s] = 3 - vis[to.first];
      len[to.second] = l;
      break;
    }
    if (fg) continue;
    for (auto &to : g[s]) if (d[to.first] == l) {
      fg = true;
      vis[s] = 1; vis[to.first] = 2;
      len[to.second] = l;
      break;
    }
    if (!fg) return !printf("%d\n", -1);
  }
  rep(i, n) putchar(vis[i] == 1 ? 'W' : 'B');
  putchar('\n');
  rep(i, m) printf("%d\n", len[i]);
  return 0;
}
