#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const long long mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int n, m;
vector<vector<pair<int, int> > > g;
vector<int> a, b, c, vis, res;
void dfs(int v, int t) {
  vis[v] = t;
  for (auto p : g[v]) {
    int u = p.first, id = p.second;
    if (vis[u] != t && a[u] <= a[v]) {
      res[id] = a[v];
      dfs(u, t);
      b[v] = b[u] ^ 1;
      break;
    }
  }
}
int main() {
  cin >> n >> m;
  g = vector<vector<pair<int, int> > >(n);
  a = vis = b = vector<int>(n);
  c = res = vector<int>(m);
  for (auto &i : a) cin >> i;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back({v, i});
    g[v].push_back({u, i});
  }
  bool B = 0;
  for (int i = 0; i < n; i++) {
    bool flag = 1;
    for (auto p : g[i]) {
      int v = p.first;
      if (a[v] <= a[i]) flag = 0;
    }
    B |= flag;
  }
  if (B) {
    cout << -1 << endl;
    return 0;
  }
  int id = 0;
  for (int i = 0; i < n; i++)
    if (!vis[i]) {
      dfs(i, ++id);
    }
  for (int i = 0; i < n; i++) cout << (b[i] ? 'B' : 'W');
  cout << endl;
  for (int i = 0; i < m; i++) {
    if (!res[i])
      cout << 1000000000 << endl;
    else
      cout << res[i] << endl;
  }
}
