#include <bits/stdc++.h>
using namespace std;
int n, m, d[200020];
struct edge {
  int id, next, to;
  edge(int id, int next, int to) : id(id), next(next), to(to) {}
  edge() {}
} e[400020 << 1];
int cnt = 1, h[200020];
int v[400020];
void Add_Edge(int id, int x, int y) {
  e[++cnt] = edge(id, h[x], y);
  h[x] = cnt;
  e[++cnt] = edge(id, h[y], x);
  h[y] = cnt;
}
struct point {
  int id, d;
  point(int id, int d) : id(id), d(d) {}
  point() {}
  bool operator<(const point b) const {
    return (d == b.d) ? id < b.id : d < b.d;
  }
} p[200020];
int c[200020];
int main() {
  int x, y;
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n; i++)
    scanf("%d", &d[i]), p[i] = point(i, d[i]);
  sort(p + 1, p + 1 + n);
  for (register int i = 1; i <= m; i++)
    scanf("%d%d", &x, &y), Add_Edge(i, x, y);
  for (register int i = 1; i <= n; i++) {
    int x = p[i].id;
    assert(p[i].d == d[x]);
    bool f = 0;
    for (register int i = h[x]; i; i = e[i].next) {
      int op = e[i].to;
      if (c[op]) {
        v[e[i].id] = d[x];
        c[x] = 3 - c[op];
        f = 1;
        break;
      }
    }
    if (!f) {
      bool f2 = 0;
      for (register int i = h[x]; i; i = e[i].next) {
        int op = e[i].to;
        if (!c[op] && d[op] == d[x]) {
          c[op] = 1, c[x] = 2, v[e[i].id] = d[x];
          f2 = 1;
          break;
        }
      }
      if (!f2) {
        printf("-1");
        return 0;
      }
    }
  }
  for (register int i = 1; i <= n; i++) {
    if (c[i] == 1)
      printf("B");
    else
      printf("W");
  }
  printf("\n");
  for (register int i = 1; i <= m; i++) {
    if (!v[i])
      printf("1000000000\n");
    else
      printf("%d\n", v[i]);
  }
  return 0;
}
