#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long linf = 1LL << 62;
const int MAX = 510000;
long long dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
long long dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const double pi = acos(-1);
const double eps = 1e-7;
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
template <typename T1, typename T2>
inline void print2(T1 a, T2 b) {
  cout << a << " " << b << endl;
}
template <typename T1, typename T2, typename T3>
inline void print3(T1 a, T2 b, T3 c) {
  cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> d(n);
  for (long long i = 0; i < (n); i++) cin >> d[i];
  vector<long long> dist(n);
  for (long long i = 0; i < (n); i++) dist[i] = d[i];
  vector<vector<long long> > G(n);
  sort((d).begin(), (d).end());
  map<pair<long long, long long>, long long> edges;
  for (long long i = 0; i < (m); i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    if (u > v) swap(u, v);
    G[u].push_back(v);
    G[v].push_back(u);
    edges[{u, v}] = i;
  }
  vector<long long> ans_v(n, -1);
  vector<long long> ans_e(m, 1e9);
  for (long long i = 0; i < (n); i++) {
    if (ans_v[i] != -1) {
      for (auto v : G[i]) {
        if (ans_v[v] == -1) {
          ans_v[v] = 1 - ans_v[i];
          ans_e[edges[{min(i, v), max(i, v)}]] = dist[v];
        }
      }
    } else {
      bool flag = false;
      for (auto v : G[i]) {
        if (dist[v] == dist[i]) {
          flag = true;
          ans_e[edges[{min(i, v), max(i, v)}]] = dist[i];
          ans_v[i] = 0;
          ans_v[v] = 1;
          break;
        }
      }
      if (!flag) {
        cout << -1 << endl;
        return 0;
      }
      for (auto v : G[i]) {
        if (ans_v[v] == -1) {
          ans_v[v] = 1 - ans_v[i];
          ans_e[edges[{min(i, v), max(i, v)}]] = dist[v];
        }
      }
    }
  }
  for (long long i = 0; i < (n); i++) cout << (ans_v[i] == 0 ? "B" : "W");
  cout << endl;
  for (long long i = 0; i < (m); i++) cout << ans_e[i] << endl;
}
