#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && (c != '-')) c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
const int N = 2e5 + 10;
int n, m, a[N], ans[N], c[N];
pair<int, int> b[N];
bool vis[N];
vector<pair<int, int> > e[N];
int main() {
  n = read(), m = read();
  for (register int i = (1); i <= (n); i++)
    a[i] = read(), b[i] = make_pair(a[i], i);
  for (register int i = (1); i <= (m); i++) {
    int x = read(), y = read();
    e[x].emplace_back(y, i), e[y].emplace_back(x, i);
  }
  sort(b + 1, b + 1 + n);
  for (register int i = (1); i <= (n); i++) {
    int u = b[i].second;
    bool flag = 0;
    for (auto v : e[u])
      if (vis[v.first]) {
        ans[v.second] = a[u];
        if (!flag) c[u] = c[v.first] ^ 1, flag = 1;
      }
    vis[u] = 1;
  }
  for (register int i = (1); i <= (n); i++) {
    bool flag = 0;
    for (auto v : e[i])
      if (ans[v.second] == a[i]) {
        flag = 1;
        break;
      }
    if (!flag) return puts("-1"), 0;
  }
  for (register int i = (1); i <= (n); i++) printf("%c", c[i] == 0 ? 'W' : 'B');
  puts("");
  for (register int i = (1); i <= (m); i++)
    printf("%d\n", ans[i] == 0 ? 1000000000 : ans[i]);
}
