#include <bits/stdc++.h>
#pragma warning(disable : 4996)
const long long MOD = 1000000007;
using namespace std;
vector<vector<pair<int, int> > > g;
vector<int> flag;
void dfs(int par, int curr, int flag_curr) {
  assert(flag_curr);
  flag[curr] = flag_curr;
  int siz = (int)g[curr].size();
  int i;
  for (i = 0; i < siz; i++) {
    int next = g[curr][i].first;
    if (next == par) continue;
    if (flag[next]) continue;
    dfs(curr, next, 3 - flag_curr);
  }
  return;
}
int main(int argc, char* argv[]) {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> d(n);
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d", &d[i]);
  }
  g.resize(n);
  vector<int> ans(m);
  vector<int> minval(n, 2140000000);
  for (i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    ans[i] = ((d[u]) < (d[v]) ? (d[v]) : (d[u]));
    minval[u] = ((minval[u]) > (ans[i]) ? (ans[i]) : (minval[u]));
    minval[v] = ((minval[v]) > (ans[i]) ? (ans[i]) : (minval[v]));
  }
  for (i = 0; i < n; i++) {
    if (minval[i] != d[i]) {
      printf("-1\n");
      return 0;
    }
  }
  flag.resize(n);
  dfs(-1, 0, 1);
  vector<char> aa;
  for (i = 0; i < n; i++) {
    if (flag[i] == 1)
      aa.push_back('B');
    else
      aa.push_back('W');
  }
  aa.push_back('\0');
  printf("%s\n", &aa[0]);
  for (i = 0; i < n; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
