#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;
constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;
constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1},
              dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
constexpr int maxi = 1000000000;
template <typename T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
void dfs(int v, int pre, vector<int>& col, vector<int>& w,
         const vector<vector<int> >& g, const vector<P>& es,
         const vector<lint>& d, lint sum = 0) {
  for (auto k : g[v]) {
    int to = es[k].first;
    if (to == v) {
      to = es[k].second;
    }
    if (to == pre) {
      continue;
    }
    if (col[to] >= 0) {
      w[k] = maxi;
    }
  }
  for (auto k : g[v]) {
    int to = es[k].first;
    if (to == v) {
      to = es[k].second;
    }
    if (col[to] == -1) {
      if (d[v] == d[to]) {
        col[to] = col[v] ^ 1;
        w[k] = d[v];
        dfs(to, v, col, w, g, es, d, w[k]);
      } else if (d[v] < d[to]) {
        col[to] = col[v];
        w[k] = d[to] - d[v];
        dfs(to, v, col, w, g, es, d, sum + d[to] - d[v]);
      }
    }
  }
  return;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, m;
  cin >> n >> m;
  vector<lint> d(n);
  for (int i = 0, i_len = (int)(n); i < i_len; ++i) {
    cin >> d[i];
  }
  vector<vector<int> > g(n);
  vector<P> es;
  for (int i = 0, i_len = (int)(m); i < i_len; ++i) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    g[u].emplace_back(i);
    g[v].emplace_back(i);
    es.emplace_back(u, v);
  }
  vector<int> col(n, -1);
  col[0] = 0;
  vector<int> w(m, -1);
  dfs(0, -1, col, w, g, es, d);
  for (int i = 0, i_len = (int)(n); i < i_len; ++i) {
    if (col[i] == -1) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0, i_len = (int)(m); i < i_len; ++i) {
    if (w[i] == -1) {
      cout << -1 << endl;
      return 0;
    }
  }
  bool ok = false;
  for (int i = 0, i_len = (int)(n - 1); i < i_len; ++i) {
    if (col[i] != col[i + 1]) {
      ok = true;
      break;
    }
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }
  string c = "BW";
  for (int i = 0, i_len = (int)(n); i < i_len; ++i) {
    cout << c[col[i]];
  }
  cout << endl;
  for (int i = 0, i_len = (int)(m); i < i_len; ++i) {
    cout << w[i] << endl;
  }
  cout << flush;
  return 0;
}
