#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30);
const long long INFLL = (1ll << 60);
const long long MOD = (long long)(1e9 + 7);
void mul_mod(long long& a, long long b) {
  a *= b;
  a %= MOD;
}
void add_mod(long long& a, long long b) {
  a = (a < MOD) ? a : (a - MOD);
  b = (b < MOD) ? b : (b - MOD);
  a += b;
  a = (a < MOD) ? a : (a - MOD);
}
bool visited[100100], tree[225816], color[100100];
int a[225816], b[225816], ans[225816], d[100100];
vector<pair<int, int> > g[100100];
pair<int, int> x[100100];
void dfs(int v) {
  int i = 0, u, e;
  visited[v] = true;
  for (i = (g[v].size() - 1); i >= 0; --i) {
    u = g[v][i].first;
    e = g[v][i].second;
    if (ans[e] < d[u]) {
      ans[e] = d[u];
    }
    if (visited[u]) {
      continue;
    }
    color[u] = (!color[v]);
    dfs(u);
  }
}
int main(void) {
  int n, m, i, j;
  bool flag = false;
  cin >> n >> m;
  for (i = 0; i < n; ++i) {
    cin >> d[i];
    x[i] = pair<int, int>(d[i], i);
  }
  sort(x, x + n);
  for (j = 0; j < m; ++j) {
    cin >> a[j] >> b[j];
    --a[j];
    --b[j];
    if (a[j] > b[j]) {
      swap(a[j], b[j]);
    }
    if (a[j] == x[0].second && b[j] == x[1].second) {
      flag = true;
    }
    g[a[j]].push_back(pair<int, int>(b[j], j));
    g[b[j]].push_back(pair<int, int>(a[j], j));
  }
  if (!(flag && x[0].first == x[1].first)) {
    cout << "-1" << endl;
    return 0;
  }
  dfs(x[0].second);
  for (i = 0; i < n; ++i) {
    cout << ((color[i]) ? "B" : "W");
  }
  cout << endl;
  for (j = 0; j < m; ++j) {
    cout << ans[j] << endl;
  }
  return 0;
}
