#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &t) {
  t = 0;
  char ch = getchar();
  int f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  do {
    (t *= 10) += ch - '0';
    ch = getchar();
  } while ('0' <= ch && ch <= '9');
  t *= f;
}
const int INF = (1e9);
const int maxn = (2e5) + 10;
int n, m, ans[maxn];
int d[maxn], p[maxn], op[maxn];
vector<int> g[maxn], id[maxn];
void add(int x, int y, int z) {
  g[x].push_back(y);
  id[x].push_back(z);
}
bool cmp(int x, int y) { return d[x] < d[y]; }
int main() {
  read(n);
  read(m);
  int x, y, z, flag;
  for (int i = 1; i <= n; i++) read(d[i]), p[i] = i, op[i] = -1;
  sort(p + 1, p + n + 1);
  for (int i = 1; i <= m; i++) read(x), read(y), add(x, y, i), add(y, x, i);
  for (int I = 1, u; I <= n; I++) {
    u = p[I];
    if (op[u] > -1) continue;
    flag = 0;
    for (int i = 0, v; i < g[u].size(); i++) {
      v = g[u][i];
      z = id[u][i];
      if (d[u] >= d[v]) {
        flag = 1;
        if (op[v] == -1)
          op[v] = 0, op[u] = 1;
        else
          op[u] = op[v] ^ 1;
        ans[z] = d[u];
        break;
      }
    }
    if (!flag) {
      printf("-1\n");
      return 0;
    }
  }
  for (int i = 1; i <= n; i++)
    if (op[i])
      printf("B");
    else
      printf("W");
  printf("\n");
  for (int i = 1; i <= m; i++) {
    if (!ans[i]) ans[i] = INF;
    printf("%d\n", ans[i]);
  }
  return 0;
}
