#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
struct data {
  long long u, v, c;
};
long long n, m;
string bw;
vector<data> edge;
vector<P> d;
vector<map<long long, long long>> memo;
vector<long long> lst;
bool solve();
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    d.push_back({x, i});
    bw += "-";
  }
  sort(d.begin(), d.end());
  memo.resize(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    edge.push_back({u, v, (long long)1e9});
    memo[u][v] = i;
    memo[v][u] = i;
  }
  if (solve()) {
    cout << bw << endl;
    for (int i = 0; i < m; ++i) cout << edge[i].c << endl;
  } else
    cout << -1 << endl;
  return 0;
}
bool solve() {
  if (memo[d[0].second].find(d[1].second) == memo[d[0].second].end() ||
      d[0].first != d[1].first)
    return 0;
  edge[memo[d[0].second][d[1].second]].c = d[0].first;
  bw[d[0].second] = 'B';
  bw[d[1].second] = 'W';
  lst.assign(n, -1);
  for (auto now : memo[d[0].second]) lst[now.first] = d[0].second;
  for (auto now : memo[d[1].second]) lst[now.first] = d[1].second;
  for (int i = 2; i < n; ++i) {
    P nowd = d[i];
    if (lst[nowd.second] == -1) return 0;
    int id = lst[nowd.second];
    if (bw[id] == 'B')
      bw[nowd.second] = 'W';
    else
      bw[nowd.second] = 'B';
    edge[memo[nowd.second][lst[nowd.second]]].c = nowd.first;
    for (auto now : memo[nowd.second]) lst[now.first] = nowd.second;
  }
  return 1;
}
