#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = numeric_limits<long long>::max() / 4;
constexpr long long n_max = 2e5 + 10;
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *c) { return to_string((string)c); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) res += ", ";
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
template <class T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
struct edge {
  long long f, t;
  T c;
  long long id;
  edge(){};
  edge(long long f, long long t, T c, long long id = 0)
      : f(f), t(t), c(c), id(id){};
  bool operator<(const edge &rhs) const { return (*this).c < rhs.c; }
  bool operator>(const edge &rhs) const { return (*this).c > rhs.c; }
  friend string to_string(edge<T> e) {
    return "(" + to_string(e.f) + ", " + to_string(e.t) + ", " +
           to_string(e.c) + ")";
  }
};
template <typename T>
struct graph {
  std::vector<std::vector<edge<T>>> data;
  graph(){};
  graph(long long v) : data(v){};
  void resize(long long n) { data.resize(n); }
  void add_edge(edge<T> &e) { data[e.f].push_back(e); }
  void add_edge(long long f, long long t, T c) {
    data[f].emplace_back(f, t, c);
  }
  size_t size() { return data.size(); }
  vector<edge<T>> operator[](long long n) { return data[n]; }
  std::vector<edge<T>> make_edges() {
    std::vector<edge<T>> r;
    for (auto &i : data) std::copy(i.begin(), i.end(), std::back_inserter(r));
    return r;
  }
};
template <typename T>
vector<long long> prim(graph<T> &g, long long root) {
  const long long n = g.size();
  bitset<n_max> used(0);
  priority_queue<edge<T>, vector<edge<T>>, greater<edge<T>>> pq;
  for (auto &e : g.data[root]) {
    pq.emplace(e);
  }
  used[root] = 1;
  vector<edge<T>> ret;
  vector<long long> state(n);
  while (!pq.empty() && used.count() < n) {
    auto e = pq.top();
    pq.pop();
    long long st = state[e.f] ^ 1;
    if (used[e.t]) continue;
    used[e.t] = 1;
    state[e.t] = st;
    ret.emplace_back(e);
    for (auto &ed : g.data[e.t]) {
      if (used[ed.t]) continue;
      pq.emplace(ed);
    }
  }
  42;
  return state;
}
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  vector<long long> d(n);
  for (long long i = 0; i < n; i++) cin >> d[i];
  vector<pair<long long, long long>> e(m);
  graph<long long> g(n);
  for (long long i = (long long)(0); i < (long long)(m); i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    g.add_edge(u, v, max(d[u], d[v]));
    g.add_edge(v, u, max(d[u], d[v]));
    e[i] = {u, v};
  }
  bool ok = true;
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    long long mi = INF;
    for (auto &ed : g[i]) chmin(mi, ed.c);
    ok &= mi == d[i];
  }
  if (!ok) {
    cout << -1 << "\n";
    return 0;
  }
  auto state = prim(g, 0);
  42;
  string ans;
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    if (state[i])
      ans += "B";
    else
      ans += "W";
  }
  cout << ans << "\n";
  for (long long i = (long long)(0); i < (long long)(m); i++) {
    auto [f, t] = e[i];
    cout << max(d[f], d[t]) << "\n";
  }
}
