#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, m, v1[N], x[N], y[N], co[N], ans[N];
pair<int, int> v2[N];
vector<int> e[N];
void color(int x) {
  for (auto i : e[x])
    if (!co[i]) co[i] = co[x] ^ 3, color(i);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (int)(1); i <= (int)(n); i++) {
    scanf("%d", &v1[i]);
    v2[i].first = 1ll << 30;
  }
  for (int i = (int)(1); i <= (int)(m); i++) {
    scanf("%d%d", &x[i], &y[i]);
    v2[y[i]] = min(v2[y[i]], pair<int, int>(v1[x[i]], i));
    v2[x[i]] = min(v2[x[i]], pair<int, int>(v1[y[i]], i));
  }
  for (int i = (int)(1); i <= (int)(n); i++)
    if (v2[i].first > v1[i]) return puts("-1"), 0;
  for (int i = (int)(1); i <= (int)(m); i++) ans[i] = 1000000000;
  for (int i = (int)(1); i <= (int)(n); i++) ans[v2[i].second] = v1[i];
  for (int i = (int)(1); i <= (int)(m); i++)
    e[x[v2[i].second]].push_back(y[v2[i].second]);
  for (int i = (int)(1); i <= (int)(m); i++)
    e[y[v2[i].second]].push_back(x[v2[i].second]);
  for (int i = (int)(1); i <= (int)(n); i++)
    if (co[i] == 0) co[i] = 1, color(i);
  for (int i = (int)(1); i <= (int)(n); i++) putchar(co[i] == 1 ? 'B' : 'W');
  puts("");
  for (int i = (int)(1); i <= (int)(m); i++) printf("%d\n", ans[i]);
}
