#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<long long> d(n);
  for (int i = 0; i < n; i++) cin >> d[i];
  vector<pair<int, int>> ed(m);
  vector<vector<int>> ad(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    ed[i] = {a, b};
    ad[a].push_back(b);
    ad[b].push_back(a);
  }
  vector<int> ind(n);
  for (int i = 0; i < n; i++) ind[i] = i;
  sort(ind.begin(), ind.end(), [&](int i0, int i1) { return d[i0] < d[i1]; });
  if (d[ind[0]] != d[ind[1]]) {
    cout << -1 << "\n";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    bool bo2 = false;
    for (int ch : ad[i]) {
      if (d[ch] <= d[i]) {
        bo2 = true;
      }
    }
    if (!bo2) {
      cout << -1 << "\n";
      return 0;
    }
  }
  map<pair<int, int>, long long> mp;
  vector<vector<int>> ad2(n);
  for (int i = 0; i < n; i++) {
    int cur = ind[i];
    int par = -1;
    for (int ch : ad[cur]) {
      if (par == -1)
        par = ch;
      else {
        if (d[par] > d[ch]) par = ch;
      }
    }
    ad2[cur].push_back(par);
    ad2[par].push_back(cur);
    for (int ch : ad[cur]) {
      mp[{cur, ch}] = 1000000000;
      mp[{ch, cur}] = 1000000000;
    }
    mp[{cur, par}] = d[cur];
    mp[{par, cur}] = d[cur];
  }
  vector<int> c(n);
  function<void(int, int)> dfs = [&](int cur, int par) {
    for (int ch : ad2[cur]) {
      if (ch == par) continue;
      if (c[ch] == 0) {
        c[ch] = 3 - c[cur];
        dfs(ch, cur);
      }
    }
  };
  for (int i = 0; i < n; i++) {
    if (c[i] == 0) {
      c[i] = 1;
      dfs(i, -1);
    }
  }
  for (int i = 0; i < n; i++) {
    if (c[i] == 1)
      cout << "W";
    else
      cout << "B";
  }
  cout << "\n";
  for (int i = 0; i < m; i++) {
    cout << mp[ed[i]] << "\n";
  }
  return 0;
}
