#include <bits/stdc++.h>
template <class Cost = int>
struct Edge {
  int src, dst;
  Cost cost;
  Edge(int src = -1, int dst = -1, Cost cost = 1)
      : src(src), dst(dst), cost(cost){};
  bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
  bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};
template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;
constexpr int INF = 1 << 30;
void solve() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> ds(n);
  std::vector<std::pair<int, int>> sds(n);
  for (int i = 0; i < n; ++i) {
    auto& d = ds[i];
    std::cin >> d;
    sds[i] = std::make_pair(d, i);
  }
  std::sort(sds.begin(), sds.end());
  Edges<int> es(m);
  std::vector<std::vector<int>> graph(n);
  for (int i = 0; i < m; ++i) {
    auto& e = es[i];
    std::cin >> e.src >> e.dst;
    --e.src, --e.dst;
    e.cost = 1e9;
    graph[e.src].push_back(i);
    graph[e.dst].push_back(i);
  }
  std::vector<int> cs(n, -1);
  for (auto p : sds) {
    int v = p.second;
    int eid = -1, dmin = INF;
    for (int i : graph[v]) {
      const auto& e = es[i];
      int u = e.src;
      if (u == v) u = e.dst;
      if (e.cost == ds[v]) {
        eid = i;
        dmin = e.cost;
        break;
      }
      if (ds[u] < dmin) {
        eid = i;
        dmin = ds[u];
      }
    }
    if (ds[v] < dmin) {
      std::cout << -1 << std::endl;
      return;
    }
    auto& e = es[eid];
    int u = e.src;
    if (u == v) u = e.dst;
    cs[v] = (cs[u] < 0 ? 0 : 1 - cs[u]);
    e.cost = ds[v];
  }
  for (int v = 0; v < n; ++v) {
    int min = INF;
    for (int i : graph[v]) {
      const auto& e = es[i];
      int u = e.src;
      if (u == v) u = e.dst;
      if (cs[u] != cs[v]) min = std::min(min, e.cost);
    }
    assert(min <= ds[v]);
  }
  for (auto c : cs) std::cout << "BW"[c];
  std::cout << std::endl;
  for (const auto& e : es) std::cout << e.cost << std::endl;
}
int main() {
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  std::ios::sync_with_stdio(false);
  solve();
  return 0;
}
