#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int M = 2e5 + 5;
int f[N << 1];
int n;
int w[M];
struct inf {
  int v, d;
} a[N];
int d[N];
vector<int> e[N];
vector<int> eu[N];
int gtf(int x) { return f[x] == x ? x : f[x] = gtf(f[x]); }
bool cmp(inf a, inf b) { return a.d < b.d; }
void adden(int x, int y) {
  f[gtf(x)] = y + n;
  f[gtf(y)] = x + n;
}
bool ckac(int x, int y) { return gtf(x) == gtf(y) || gtf(x) == gtf(y + n); }
int main() {
  int m, i, j, u, v;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    a[i].v = i, a[i].d = d[i];
  }
  for (i = 1; i <= 2 * n; i++) f[i] = i;
  sort(a + 1, a + n + 1, cmp);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    e[u].push_back(v), eu[u].push_back(i);
    e[v].push_back(u), eu[v].push_back(i);
  }
  for (i = 1; i <= n; i++) {
    int t = 1e9;
    for (j = 0; j < e[i].size(); j++)
      if (!ckac(i, e[i][j]))
        w[eu[i][j]] = d[e[i][j]], adden(i, e[i][j]), t = min(t, d[e[i][j]]);
      else
        w[eu[i][j]] = 1e9;
    if (t != d[i]) {
      printf("-1\n");
      return 0;
    }
  }
  for (i = 1; i <= n; i++)
    if (gtf(i) == gtf(1))
      printf("W");
    else
      printf("B");
  printf("\n");
  for (i = 1; i <= m; i++) printf("%d\n", w[i]);
  return 0;
}
