#include <bits/stdc++.h>
using namespace std;
vector<long long> g[200010];
long long n, m, a[200010], b[200010], c[200010], d[200010], len[200010];
vector<long long> f[200010];
bool us[200010];
long long col[200010];
void dfs(long long x, bool co) {
  if (~col[x]) return;
  col[x] = co;
  for (auto y : f[x]) {
    dfs(y, co ^ 1);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> d[i];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    len[i] = max(d[a[i]], d[b[i]]);
    g[a[i]].push_back(i);
    g[b[i]].push_back(i);
  }
  bool ok = 1;
  for (int i = 0; i < n; i++) {
    long long mi = 1e17;
    for (auto e : g[i]) {
      if (mi > len[e]) {
        us[e] = 1;
        mi = len[e];
      }
    }
    if (d[i] != mi) ok = 0;
  }
  if (ok == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < m; i++)
    if (us[i]) {
      f[a[i]].push_back(b[i]);
      f[b[i]].push_back(a[i]);
    }
  for (int i = 0; i < n; i++) col[i] = -1;
  for (int i = 0; i < n; i++) dfs(i, 0);
  for (int i = 0; i < n; i++) cout << (col[i] ? "B" : "W");
  cout << endl;
  for (int i = 0; i < m; i++) cout << len[i] << endl;
}
