#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
vector<int> g[maxn];
int d[maxn], vis[maxn];
int ord[maxn];
int ans[maxn], u[maxn], v[maxn];
queue<int> q;
map<pair<int, int>, int> rev;
void shit() {
  puts("-1");
  exit(0);
}
bool cmp(int i, int j) { return d[i] < d[j]; }
void cdd(int x, int y, int v) {
  if (x > y) swap(x, y);
  int k = rev[make_pair(x, y)];
  ans[k] = v;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]), ord[i] = i;
  sort(ord + 1, ord + 1 + n, cmp);
  if (d[ord[2]] != d[ord[1]]) shit();
  int mini = d[ord[1]];
  memset(vis, -1, sizeof(vis));
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u[i], &v[i]);
    if (u[i] > v[i]) swap(u[i], v[i]);
    rev[make_pair(u[i], v[i])] = i;
    g[u[i]].push_back(v[i]);
    g[v[i]].push_back(u[i]);
    ans[i] = 1e9;
  }
  int x = -1, y = -1;
  for (int i = 1; i <= m; i++) {
    if (d[u[i]] == mini && d[v[i]] == mini) {
      x = u[i];
      y = v[i];
      break;
    }
  }
  if (x == -1) shit();
  cdd(x, y, mini);
  vis[x] = 0;
  vis[y] = 1;
  q.push(x);
  q.push(y);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int y : g[x]) {
      if (vis[y] != -1) continue;
      if (d[y] < d[x]) continue;
      vis[y] = vis[x] ^ 1;
      cdd(x, y, d[y]);
      q.push(y);
    }
  }
  for (int i = 1; i <= n; i++)
    if (vis[i] == -1) shit();
  for (int i = 1; i <= n; i++) {
    if (vis[i])
      putchar('B');
    else
      putchar('W');
  }
  puts("");
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
