#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;
template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}
struct Edge {
  int from, to, index;
  ll cost;
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<Edge>> g(n);
  vector<Edge> es(m);
  vector<ll> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    es[i] = Edge{u, v, i, (ll)1e9};
    g[u].push_back(Edge{u, v, i, -1});
    g[v].push_back(Edge{v, u, i, -1});
  }
  vector<int> col(n, -1);
  priority_queue<P, vector<P>, greater<P>> que;
  for (int i = 0; i < n; i++) {
    que.push(P(d[i], i));
  }
  while (!que.empty()) {
    auto p = que.top();
    que.pop();
    int cur = p.second;
    int mi = INF;
    for (const auto &e : g[cur]) {
      int nxt = e.to;
      if (d[nxt] < mi) {
        mi = d[nxt];
      }
    }
    if (mi < d[cur]) {
      for (const auto &e : g[cur]) {
        int nxt = e.to, index = e.index;
        if (d[nxt] == mi) {
          assert(col[nxt] != -1);
          col[cur] = col[nxt];
          es[index].cost = d[cur] - d[nxt];
          break;
        }
      }
    } else if (mi == d[cur]) {
      bool f = false;
      for (const auto &e : g[cur]) {
        int nxt = e.to, index = e.index;
        if (d[nxt] == mi && col[nxt] != -1) {
          col[cur] = 1 - col[nxt];
          es[index].cost = d[cur];
          f = true;
          break;
        }
      }
      if (f) continue;
      col[cur] = 0;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << (col[i] ? "B" : "W");
  }
  cout << endl;
  for (int i = 0; i < m; i++) {
    cout << es[i].cost << endl;
  }
}
