#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  ll m;
  cin >> m;
  vector<pair<ll, ll>> x(m);
  vector<vector<ll>> z(n);
  map<ll, vector<ll>> mp;
  for (int i = 0; i < n; i++) {
    ll f;
    cin >> f;
    mp[f].push_back(i);
  }
  for (int i = 0; i < m; i++) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    z[a].push_back(b);
    z[b].push_back(a);
    x[i] = make_pair(min(a, b), max(a, b));
  }
  vector<char> ans(n, 'A');
  map<pair<ll, ll>, ll> anss;
  vector<bool> seen(n);
  ll l = 0;
  for (auto h : mp) {
    for (auto s : h.second) {
      seen[s] = true;
    }
    for (auto s : h.second) {
      ll fl = 1;
      for (auto d : z[s]) {
        if (seen[d]) {
          if (ans[d] == 'A') ans[d] = 'B';
          if (ans[d] == 'B')
            ans[s] = 'W';
          else
            ans[s] = 'B';
          fl = 0;
          anss[make_pair(min(s, d), max(s, d))] = h.first;
          break;
        }
      }
      if (fl == 1) l = -1;
    }
  }
  if (l == -1)
    cout << l << endl;
  else {
    for (int i = 0; i < n; i++) {
      cout << ans[i];
    }
    cout << endl;
    for (int i = 0; i < m; i++) {
      if (anss.count(x[i])) {
        cout << anss[x[i]] << endl;
      } else {
        cout << 1000000000 << endl;
      }
    }
  }
}
