#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
long long gcd(long long n, long long m) { return (m ? gcd(m, n % m) : n); }
long long lcm(long long n, long long m) { return n / gcd(n, m) * m; }
vector<vector<int>> tr;
vector<int> col(100010);
void dfs(int n, int p, bool ok) {
  if (ok) col[n] = col[p] ^ 1;
  for (int i : tr[n]) {
    if (i != p) {
      dfs(i, n, true);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  tr.assign(n, vector<int>());
  vector<int> d(n);
  for (int i = 0; i < n; i++) cin >> d[i];
  vector<vector<int>> graph(n, vector<int>());
  vector<int> u(m), v(m);
  for (int i = 0; i < m; i++) {
    cin >> u[i] >> v[i];
    u[i]--;
    v[i]--;
    graph[u[i]].push_back(v[i]);
    graph[v[i]].push_back(u[i]);
  }
  vector<pair<long long, long long>> p(n);
  for (int i = 0; i < n; i++) {
    p[i].first = d[i];
    p[i].second = i;
  }
  sort(p.begin(), p.end());
  map<pair<long long, long long>, int> mp;
  set<pair<long long, long long>> sts;
  for (int i = 0; i < n; i++) {
    int ver = p[i].second;
    if (i == 0) col[ver] = 0;
    bool flag = false;
    sort(graph[ver].begin(), graph[ver].end());
    for (int x : graph[ver]) {
      pair<long long, long long> ps;
      if (d[x] <= d[ver]) {
        ps.first = min(x, ver);
        ps.second = max(x, ver);
        mp[ps] = d[ver];
        if (!sts.count(pair<long long, long long>(x, ver)) &&
            !sts.count(pair<long long, long long>(ver, x))) {
          tr[x].push_back(ver);
          tr[ver].push_back(x);
          sts.insert(pair<long long, long long>(x, ver));
          sts.insert(pair<long long, long long>(ver, x));
        }
        flag = true;
        break;
      }
    }
    if (!flag) {
      cout << -1 << endl;
      return 0;
    }
  }
  dfs(p[0].second, -1, false);
  for (int i = 0; i < n; i++) cout << (col[i] ? "B" : "W");
  cout << endl;
  for (int i = 0; i < m; i++) {
    if (u[i] > v[i]) swap(u[i], v[i]);
    pair<long long, long long> re;
    re.first = u[i];
    re.second = v[i];
    if (mp[re] != 0)
      cout << mp[re] << endl;
    else
      cout << 1000000000 << endl;
  }
}
