#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;
  d.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> d[i].first;
    d[i].second = i;
    bw += "-";
  }
  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;
  }
  lst.assign(n, 0);
  for (int i = 0; i < n; ++i) {
    lst[i] = i;
    for (auto now : memo[i])
      if (d[lst[i]].first >= d[now.first].first) lst[i] = now.first;
    if (lst[i] == i) {
      cout << -1 << endl;
      return 0;
    }
  }
  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() {
  for (int i = 0; i < n; ++i) {
    if (bw[lst[i]] == 'B')
      bw[i] = 'W';
    else
      bw[i] = 'B';
    edge[memo[i][lst[i]]].c = d[i].first;
  }
  return 1;
}
