#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() {
  lst.assign(n, -1);
  for (int i = 0; i < n;) {
    long long numd = d[i].first, id = i;
    while (i < n && d[i].first == numd) {
      for (auto now : memo[d[i].second])
        if (edge[now.second].c == (long long)1e9) lst[now.first] = d[i].second;
      ++i;
    }
    for (int j = i - 1; j >= id; --j) {
      P nowd = d[j];
      if (lst[nowd.second] == -1) return 0;
      int nowid = lst[nowd.second];
      if (bw[nowid] == 'B')
        bw[nowd.second] = 'W';
      else
        bw[nowd.second] = 'B';
      edge[memo[nowd.second][nowid]].c = nowd.first;
    }
  }
  return 1;
}
