#include <bits/stdc++.h>
signed main() {
  const long long INF = 1e9 + 1;
  long long n, m;
  std::cin >> n >> m;
  std::vector<long long> d(n);
  for (long long i = 0; i < (n); i++) std::cin >> d[i];
  std::vector<std::pair<long long, long long> > edges;
  std::vector<std::vector<std::pair<long long, long long> > > g(
      n, std::vector<std::pair<long long, long long> >());
  for (long long i = 0; i < (m); i++) {
    long long u, v;
    std::cin >> u >> v;
    u--;
    v--;
    edges.emplace_back(u, v);
    g[u].emplace_back(v, i);
    g[v].emplace_back(u, i);
  }
  std::set<long long> use;
  for (long long i = 0; i < (n); i++) {
    long long min = INF;
    long long mini = -1;
    for (auto to : g[i]) {
      if (min > d[to.first]) {
        min = d[to.first];
        mini = to.second;
      }
    }
    if (min > d[i]) {
      std::cout << (-1) << '\n';
      return 0;
    }
    use.emplace(mini);
  }
  std::vector<long long> ans(m, 1e9);
  for (auto x : use) {
    ans[x] = std::max(d[edges[x].first], d[edges[x].second]);
  }
  std::vector<long long> col(n, -1);
  std::function<void(long long)> dfs = [&](long long i) {
    for (auto to : g[i]) {
      if (col[to.first] != -1) continue;
      col[to.first] = col[i] ^ 1;
      dfs(to.first);
    }
  };
  col[0] = 0;
  dfs(0);
  for (auto i : col) {
    if (i)
      std::cout << 'W';
    else
      std::cout << 'B';
  }
  std::cout << '\n';
  for (long long i : ans) {
    std::cout << (i) << '\n';
  }
  return 0;
}
