#include <bits/stdc++.h>
using namespace std;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
constexpr long long TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T, class U>
void chmin(T& t, const U& u) {
  if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
  if (t < u) t = u;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  for (int i = 0; i < (v.size()); i++) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}
const int maxn = 100010;
const int L = TEN(9);
V<pair<int, int>> g[maxn];
int main() {
  int N, M;
  cin >> N >> M;
  V<int> D(N);
  for (int i = 0; i < (N); i++) cin >> D[i];
  V<pair<int, int>> es(M);
  for (int i = 0; i < (M); i++) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a].emplace_back(b, i);
    g[b].emplace_back(a, i);
  }
  V<pair<int, int>> vec;
  for (int i = 0; i < (N); i++) vec.emplace_back(make_pair(D[i], i));
  sort((vec).begin(), (vec).end());
  V<int> ans(M, L);
  V<int> col(N, -1);
  for (int i = 0; i < (N); i++) {
    int v = vec[i].second;
    cerr << 70 << " "
         << "v"
         << " = " << (v) << endl;
    if (col[v] != -1) {
      continue;
    }
    bool fd = 0;
    for (auto e : g[v]) {
      if (col[e.first] != -1) {
        if (D[e.first] == D[v]) {
          col[v] = col[e.first] ^ 1;
          cerr << 79 << " "
               << "mp(v, e.fi)"
               << " = " << (make_pair(v, e.first)) << endl;
          cerr << 80 << " "
               << "D[v]"
               << " = " << (D[v]) << endl;
          ans[e.second] = D[v];
        } else {
          col[v] = col[e.first];
          ans[e.second] = D[v] - D[e.first];
          cerr << 85 << " "
               << "mp(v, e.fi)"
               << " = " << (make_pair(v, e.first)) << endl;
          cerr << 86 << " "
               << "D[v] - D[e.fi]"
               << " = " << (D[v] - D[e.first]) << endl;
        }
        fd = 1;
        break;
      } else {
        if (D[v] == D[e.first]) {
          col[e.first] = 0;
          col[v] = 1;
          ans[e.second] = D[v];
          cerr << 95 << " "
               << "e.se"
               << " = " << (e.second) << endl;
          cerr << 96 << " "
               << "D[v]"
               << " = " << (D[v]) << endl;
          fd = 1;
          break;
        }
      }
    }
    if (!fd) {
      puts("-1");
      return 0;
    }
    cerr << 106 << " "
         << "ans"
         << " = " << (ans) << endl;
  }
  string s(N, '?');
  for (int i = 0; i < (N); i++) {
    if (col[i] == 1)
      s[i] = 'B';
    else
      s[i] = 'W';
  }
  cout << s << endl;
  for (int i = 0; i < (M); i++) {
    cout << ans[i] << "\n";
  }
  return 0;
}
