#include <bits/stdc++.h>
constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct E {
  int to, index;
};
using G = vector<vector<E>>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vi d(n);
  for (ll i = 0; i < ll(n); ++i) cin >> d[i];
  G g(n);
  for (ll i = 0; i < ll(m); ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back({b, (int)i});
    g[b].push_back({a, (int)i});
  }
  vi wei(m, -1);
  vi col(n, -1);
  {
    int cnt = 0;
    int mi = *min_element((d).begin(), (d).end());
    for (ll i = 0; i < ll(n); ++i)
      if (d[i] == mi) cnt++;
    if (cnt == 1) {
      cout << -1 << endl;
      return 0;
    }
    vi ok(n);
    for (ll i = 0; i < ll(n); ++i)
      for (auto e : g[i]) {
        if (d[i] == mi && d[e.to] == mi) {
          ok[i] = 1;
          ok[e.to] = 1;
          wei[e.index] = mi;
          if (col[i] == -1 && col[e.to] == -1) {
            col[i] = 0;
            col[e.to] = 1;
          } else if (col[i] == -1) {
            col[i] = 1 - col[e.to];
          } else if (col[e.to] == -1) {
            col[e.to] = 1 - col[i];
          }
        }
      }
    for (ll i = 0; i < ll(n); ++i) {
      if (d[i] == mi && ok[i] == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int mi = *min_element((d).begin(), (d).end());
  auto cmp = [&](int a, int b) { return d[a] > d[b]; };
  priority_queue<int, vi, decltype(cmp)> q(cmp);
  for (ll i = 0; i < ll(n); ++i) {
    if (d[i] > mi) q.push(i);
  }
  while (!q.empty()) {
    int p = q.top();
    q.pop();
    bool ok = false;
    for (auto e : g[p]) {
      if (col[e.to] != -1) {
        col[p] = 1 - col[e.to];
        wei[e.index] = d[p];
        ok = true;
        break;
      }
    }
    if (!ok) {
      for (auto e : g[p]) {
        if (d[e.to] == d[p]) {
          col[p] = 0;
          col[e.to] = 1;
          wei[e.index] = d[p];
          ok = true;
          break;
        }
      }
    }
    if (!ok) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (ll i = 0; i < ll(n); ++i) {
    cout << "BW"[col[i]];
  }
  cout << endl;
  for (ll i = 0; i < ll(m); ++i) {
    if (wei[i] == -1)
      cout << 1000000001ll - 1 << endl;
    else
      cout << wei[i] << endl;
  }
}
