#include <bits/stdc++.h>
using namespace std;
constexpr int kMaxC = 1000000000;
struct Edge {
  int u, v, c;
};
struct Node {
  int i, d;
  char color;
  vector<Edge*> edges;
};
bool operator<(const Node& u, const Node& v) {
  if (u.d != v.d) return u.d < v.d;
  if (u.i != v.i) return u.i < v.i;
  return false;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<Node> nodes(n);
  for (int i = 0; i < n; i++) {
    int d;
    scanf("%d", &d);
    nodes[i] = {i, d, '?', {}};
  }
  vector<Edge> edges(m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edges[i] = {--u, --v, kMaxC};
    nodes[u].edges.push_back(&edges[i]);
    nodes[v].edges.push_back(&edges[i]);
  }
  sort(nodes.begin(), nodes.end());
  for (Node& v : nodes) {
    for (Edge* e : v.edges) {
      int u_i = (e->u != v.i) ? e->u : e->v;
      Node& u = nodes[u_i];
      if (u.d == v.d || u.color != '?') {
        v.color = (u.color == 'B') ? 'W' : 'B';
        u.color = (v.color == 'B') ? 'W' : 'B';
        e->c = v.d;
        break;
      }
    }
    if (v.color == '?') {
      puts("-1");
      return 0;
    }
  }
  for (int i = 0; i < n; i++) putchar(nodes[i].color);
  putchar('\n');
  for (int i = 0; i < m; i++) printf("%d\n", edges[i].c);
  return 0;
}
