#include <bits/stdc++.h>
using namespace std;
template <class T>
struct edge {
  int to;
  T wt;
  edge(int to, const T& wt) : to(to), wt(wt) {}
};
template <class T>
using weighted_graph = vector<vector<edge<T>>>;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> val(n);
  for (int u = 0; u < (n); u++) scanf("%d", &val[u]);
  weighted_graph<int> G(n);
  for (int i = 0; i < (m); i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    G[u].emplace_back(v, i);
    G[v].emplace_back(u, i);
  }
  vector<pair<int, int>> p(n);
  for (int u = 0; u < (n); u++) p[u] = {val[u], u};
  sort(p.begin(), p.end());
  vector<int> color(n, -1), wt(m, 1e9);
  for (int i = 0; i < (n); i++) {
    int u = p[i].second;
    int to = -1, id;
    for (auto e : G[u])
      if (val[e.to] <= val[u]) {
        to = e.to;
        id = e.wt;
        break;
      }
    if (to == -1) return puts("-1"), 0;
    color[u] = (color[to] == -1 ? 0 : 1 - color[to]);
    wt[id] = val[u];
  }
  for (int u = 0; u < (n); u++) putchar(color[u] == 0 ? 'B' : 'W');
  puts("");
  for (int i = 0; i < (m); i++) printf("%d\n", wt[i]);
  return 0;
}
