#include <bits/stdc++.h>
using namespace std;
const int nax = 1e5;
vector<pair<int, int>> node[nax];
vector<int> child[nax];
int weight[nax * 2], par[nax];
int col[nax];
void dfs(int p, int c) {
  if (col[p]) return;
  col[p] = c;
  for (int i : child[p]) dfs(i, 3 - c);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    node[a].emplace_back(b, i);
    node[b].emplace_back(a, i);
    weight[i] = 1e9;
  }
  for (int i = 0; i < n; i++) {
    par[i] = -1;
    for (auto pa : node[i]) {
      auto [j, ei] = pa;
      if (d[j] <= d[i]) {
        weight[ei] = d[i];
        par[i] = j;
        if (d[j] == d[i]) {
          par[j] = i;
        }
      }
    }
    if (par[i] == -1) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) child[par[i]].push_back(i);
  for (int i = 0; i < n; i++) {
    if (par[par[i]] == i) {
      dfs(i, 1);
    }
  }
  for (int i = 0; i < n; i++) cout << (col[i] == 2 ? "B" : "W");
  cout << '\n';
  for (int i = 0; i < m; i++) cout << weight[i] << '\n';
}
