#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int INF = 1e9;
int used[N];
namespace DSU {
int p[N];
int rank[N];
int get(int v) {
  if (p[v] != v) {
    p[v] = get(p[v]);
  }
  return p[v];
}
void merge(int a, int b) {
  a = get(a);
  b = get(b);
  if (rank[a] < rank[b]) swap(a, b);
  p[b] = a;
  if (rank[a] == rank[b]) rank[a]++;
}
void init() {
  for (int i = 0; i < N; i++) {
    p[i] = i;
  }
}
}  // namespace DSU
struct Edge {
  int u, v, ind;
  Edge() {}
  Edge(int u_, int v_, int ind_) {
    u = u_;
    v = v_;
    ind = ind_;
  }
};
int d[N];
int cl[N];
int ans[2 * N];
void run(int cd, vector<int> vals, vector<Edge> in, vector<Edge> out) {
  for (auto t : in) {
    if (DSU::get(t.u) != DSU::get(t.v)) {
      if (!used[t.u] && !used[t.v]) {
        cl[t.u] = 0;
        cl[t.v] = 1;
      } else if (!used[t.u]) {
        cl[t.u] = 1 ^ cl[t.v];
      } else {
        cl[t.v] = 1 ^ cl[t.u];
      }
      ans[t.ind] = cd;
      DSU::merge(t.u, t.v);
      used[t.u] = 1;
      used[t.v] = 1;
    }
  }
  for (auto t : out) {
    if (used[t.v]) continue;
    cl[t.v] = cl[t.u];
    ans[t.ind] = d[t.v] - d[t.u];
    used[t.v] = 1;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  DSU::init();
  int n, m;
  cin >> n >> m;
  map<int, vector<int>> ind;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    ind[d[i]].push_back(i);
  }
  map<int, vector<Edge>> in;
  map<int, vector<Edge>> out;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    if (d[u] > d[v]) swap(u, v);
    if (d[u] == d[v]) {
      in[d[u]].push_back(Edge(u, v, i));
    } else {
      out[d[v]].push_back(Edge(u, v, i));
    }
  }
  fill(ans, ans + m, INF);
  fill(cl, cl + N, -1);
  for (auto t : ind) {
    run(t.first, t.second, in[t.first], out[t.first]);
  }
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      cout << -1 << endl;
      exit(0);
    }
  }
  for (int i = 0; i < n; i++) {
    cout << (cl[i] ? 'B' : 'W');
  }
  cout << endl;
  for (int i = 0; i < m; i++) {
    cout << ans[i] << '\n';
  }
}
