#include <bits/stdc++.h>
using namespace std;
const int N = 222222;
int a[N], vst[N], ans[N], col[N];
vector<pair<int, int> > e[N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i(1); i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i(1); i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[x].push_back({y, i});
    e[y].push_back({x, i});
  }
  set<pair<int, int> > st;
  for (int i(1); i <= n; i++) {
    for (pair<int, int> tmp : e[i]) {
      int y = tmp.first;
      if (a[i] == a[y]) {
        vst[i] = vst[y] = 1;
        col[i] = 0;
        col[y] = 1;
        ans[tmp.second] = a[i];
        st.insert({a[i], i});
        st.insert({a[y], y});
      }
    }
  }
  for (int i(1); i <= n; i++) {
    if (st.empty()) {
      printf("-1\n");
      exit(0);
    }
    int v = st.begin()->second;
    st.erase(st.begin());
    for (pair<int, int> tmp : e[v]) {
      int y = tmp.first;
      if (!vst[y] && a[y] >= a[v]) {
        st.insert({a[y], y});
        col[y] = col[v] ^ 1;
        vst[y] = 1;
        ans[tmp.second] = a[y];
      }
    }
  }
  for (int i(1); i <= n; i++) printf("%c", col[i] ? 'B' : 'W');
  printf("\n");
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i] ? ans[i] : (int)1e9);
}
