#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using P = pair<int, int>;
vector<P> G[100010];
int d[100010], edge[200010];
bool visited[100010] = {0}, color[100010] = {0};
void dfs(int i) {
  visited[i] = true;
  for (auto &g : G[i]) {
    if (visited[g.first]) continue;
    if (d[g.first] > d[i]) {
      color[g.first] = color[i];
      edge[g.second] = d[g.first] - d[i];
    } else {
      color[g.first] = !color[i];
      edge[g.second] = d[g.first];
    }
    dfs(g.first);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int mi = (int)1e9;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    mi = min(mi, d[i]);
  }
  int root = -1;
  for (int i = 0, ui, vi; i < m; i++) {
    cin >> ui >> vi;
    ui--;
    vi--;
    if (d[ui] == mi && d[vi] == mi) root = ui;
    G[ui].push_back({vi, i});
    G[vi].push_back({ui, i});
  }
  if (root < 0) {
    cout << -1 << '\n';
    return 0;
  }
  fill(edge, edge + m, (int)1e9);
  for (int i = 0; i < n; i++) {
    sort(G[i].begin(), G[i].end(),
         [&](P l, P r) { return d[l.first] < d[r.first]; });
  }
  dfs(root);
  for (int i = 0; i < n; i++) {
    cout << (color[i] ? 'B' : 'W');
  }
  cout << '\n';
  for (int i = 0; i < m; i++) {
    cout << edge[i] << '\n';
  }
  return 0;
}
