#include <bits/stdc++.h>
int upll(const void* a, const void* b) {
  return *(long long*)a < *(long long*)b   ? -1
         : *(long long*)a > *(long long*)b ? 1
                                           : 0;
}
int downll(const void* a, const void* b) {
  return *(long long*)a < *(long long*)b   ? 1
         : *(long long*)a > *(long long*)b ? -1
                                           : 0;
}
void sortup(long long* a, int n) { qsort(a, n, sizeof(long long), upll); }
void sortdown(long long* a, int n) { qsort(a, n, sizeof(long long), downll); }
long long pom(long long a, long long n, int m) {
  long long x = 1;
  for (a %= m; n; n /= 2) n& 1 ? x = x * a % m : 0, a = a * a % m;
  return x;
}
typedef struct edge {
  long long s, g, c, f, i;
} E;
typedef struct graph {
  int vcnt, ecnt;
  E e[200010];
  int id[100010];
} G;
G g;
int a[100010];
int esort(const void* a, const void* b) {
  E *p = (E*)a, *q = (E*)b;
  if ((*p).s < (*q).s) return -1;
  if ((*p).s > (*q).s) return 1;
  if ((*p).g < (*q).g) return -1;
  return 1;
}
int csort(const void* a, const void* b) {
  long long p = (*(E*)a).c, q = (*(E*)b).c;
  return p < q ? -1 : p > q ? 1 : 0;
}
void readgraph() {
  long long n, m;
  scanf("%lld%lld", &n, &m);
  for (long long i = (0); i < (n); i++) scanf("%d", a + i);
  for (long long i = (0); i < (m); i++) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    x--, y--;
    g.e[i].s = x;
    g.e[i].g = y;
    g.e[i].c = ((a[x]) > (a[y]) ? (a[x]) : (a[y]));
    g.e[i].f = 0;
    g.e[i].i = i;
  }
  g.vcnt = n;
  g.ecnt = m;
  qsort(g.e, g.ecnt, sizeof(E), csort);
}
int unicnt[(1 << 17) + 10];
void ufinit(int n) {
  for (long long i = (0); i < (n); i++) unicnt[i] = 1;
}
int ufroot(int x) {
  return unicnt[x] <= 0 ? -(unicnt[x] = -ufroot(-unicnt[x])) : x;
}
int ufsame(int x, int y) { return ufroot(x) == ufroot(y); }
void uni(int x, int y) {
  if ((x = ufroot(x)) == (y = ufroot(y))) return;
  if (unicnt[x] < unicnt[y]) {
    int t = x;
    x = y;
    y = t;
  }
  unicnt[x] += unicnt[y];
  unicnt[y] = -x;
}
long long kurasukaru() {
  long long ans = 0;
  ufinit(g.vcnt);
  for (long long i = (0); i < (g.ecnt); i++) {
    if (!ufsame(g.e[i].s, g.e[i].g)) {
      uni(g.e[i].s, g.e[i].g);
      g.e[i].f = 1;
      ans += g.e[i].c;
    }
  }
  return ans;
}
void makeinvedge() {
  qsort(g.e, g.ecnt, sizeof(E), esort);
  int nnn = g.ecnt;
  for (long long i = (0); i < (g.ecnt); i++) {
    int l = 0, r = g.ecnt;
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (g.e[m].s < g.e[i].g || (g.e[m].s == g.e[i].g && g.e[m].g <= g.e[i].s))
        l = m;
      else
        r = m;
    }
    g.e[nnn].s = g.e[i].g;
    g.e[nnn].g = g.e[i].s;
    g.e[nnn].c = g.e[i].c;
    g.e[nnn].f = g.e[i].f;
    g.e[nnn].i = g.e[i].i;
    nnn++;
  }
  g.ecnt *= 2;
  qsort(g.e, g.ecnt, sizeof(E), esort);
  int p = 0;
  for (long long i = (0); i < (g.vcnt); i++) {
    while (p < g.ecnt && g.e[p].s < i) p++;
    g.id[i] = p;
  }
  g.id[g.vcnt] = g.ecnt;
}
int col[100010];
int dfs(int v, int pre, int c) {
  int flag = 1;
  col[v] = c;
  for (long long i = (g.id[v]); i < (g.id[v + 1]); i++) {
    if (g.e[i].f == 1 && g.e[i].g != pre) {
      flag &= (a[g.e[i].g] >= a[v]);
      flag &= dfs(g.e[i].g, v, 3 - c);
    }
  }
  return flag;
}
int ans[100010];
int main() {
  readgraph();
  kurasukaru();
  makeinvedge();
  int v = -1, m = 2e9;
  for (long long i = (0); i < (g.vcnt); i++)
    if (m > a[i]) v = i, m = a[i];
  int cnt = 0;
  for (long long i = (0); i < (g.vcnt); i++)
    if (m == a[i]) cnt++;
  if (cnt == 1) {
    puts("-1");
    return 0;
  }
  if (!dfs(v, -1, 1)) {
    puts("-1");
    return 0;
  }
  for (long long i = (0); i < (g.vcnt); i++) putchar(col[i] == 1 ? 'B' : 'W');
  puts("");
  for (long long i = (0); i < (g.ecnt); i++)
    ans[g.e[i].i] = g.e[i].f ? g.e[i].c : 1e9;
  for (long long i = (0); i < (g.ecnt / 2); i++) printf("%d\n", ans[i]);
}
