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