#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long v, idx, w;
};
long long N, M;
vector<long long> D;
vector<edge> es[100010];
long long res[100010], resC[200010];
bool solved[100010];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  D.resize(N);
  for (long long i = (long long)(0); i < (long long)(N); i++) cin >> D[i];
  for (long long i = (long long)(0); i < (long long)(M); i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    if (D[u] < D[v] || (D[u] == D[v] && u < v)) swap(u, v);
    es[u].push_back((edge){v, i, D[u]});
    res[i] = D[u];
  }
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      que;
  for (long long i = (long long)(0); i < (long long)(N); i++) {
    que.push(pair<long long, long long>(D[i], i));
  }
  while (que.size()) {
    pair<long long, long long> p = que.top();
    que.pop();
    long long v = p.second;
    long long d = p.first;
    bool ok = true;
    for (edge e : es[v]) {
      if (!solved[e.v] && D[e.v] != d) {
        ok = false;
      }
    }
    if (!ok) {
      cout << -1 << endl;
      return 0;
    }
    if (es[v].size() == 0) {
      continue;
    }
    bool col = false;
    for (edge e : es[v]) {
      solved[e.v] = true;
      if (resC[e.v] == 0) col = true;
    }
    resC[v] = col;
    solved[v] = true;
  }
  for (long long i = (long long)(0); i < (long long)(N); i++) {
    if (!solved[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (long long i = (long long)(0); i < (long long)(N); i++) {
    if (resC[i] == 0)
      cout << "W";
    else
      cout << "B";
  }
  cout << "\n";
  for (long long i = (long long)(0); i < (long long)(M); i++) {
    cout << res[i] << "\n";
  }
  return 0;
}
