#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, m, tot, c[N], a[N], head[N], nex[N], to[N], id[N];
void add(int u, int v, int i) {
  to[++tot] = v;
  nex[tot] = head[u];
  head[u] = tot;
  id[tot] = i;
}
bool vis[N];
int dis[N];
int ans;
struct node {
  int u, x;
  node(int u = 0, int x = 0) : u(u), x(x) {}
  bool operator<(const node& o) const { return x < o.x; }
};
priority_queue<node> q;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  bool flag = false;
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v, i);
    add(v, u, i);
    if (!flag && a[u] == a[v]) {
      q.push(node(u, a[u]));
      q.push(node(v, a[v]));
      c[u] = 1;
      c[v] = 0;
      vis[u] = vis[v] = true;
      ans++;
      ans++;
      dis[i] = a[u];
      flag = true;
    }
  }
  if (!flag) {
    printf("-1\n");
    return 0;
  }
  while (!q.empty()) {
    node now = q.top();
    q.pop();
    for (int i = head[now.u]; i; i = nex[i]) {
      int v = to[i];
      if (vis[v] || a[v] < now.x) continue;
      vis[v] = true;
      ans++;
      dis[id[i]] = a[v];
      c[v] = c[now.u] ^ 1;
      q.push(node(v, a[v]));
    }
  }
  if (ans != n) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1; i <= n; i++) putchar(c[i] ? 'B' : 'W');
  putchar('\n');
  for (int i = 1; i <= m; i++) printf("%d\n", !dis[i] ? 1000000000 : dis[i]);
}
