#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "<" << p.first << ", " << p.second << ">";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
  os << "[";
  for (int i = 0; i < a.size(); i++) {
    os << a[i];
    if ((i + 1) < a.size()) os << ", ";
  }
  os << "]";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp) {
  os << "[";
  for (auto itr = mp.begin(); itr != mp.end();) {
    cout << (*itr);
    itr++;
    if (itr != mp.end()) {
      cout << ", ";
    }
  }
  cout << "]";
  return os;
}
chrono::system_clock::time_point startt, endt;
double stop_watch(bool flag, string str = "") {
  if (!flag) {
    endt = chrono::system_clock::now();
    double time = static_cast<double>(
        chrono::duration_cast<chrono::microseconds>(endt - startt).count() /
        1000.0);
    cout << str << "time : " << time << " msec.\n";
    startt = chrono::system_clock::now();
    return time;
  }
  startt = chrono::system_clock::now();
  return 0;
}
template <typename T>
class BIT {
 public:
  int size;
  vector<T> arr;
  BIT(int n) {
    size = n + 5;
    arr.resize(size);
  }
  void add(int i, T v) {
    for (int x = i + 1; x < size; x += (x & (-x))) arr[x] += v;
  }
  T sum(int i) {
    i = min(i, size - 2);
    T res = 0;
    for (int x = i + 1; x > 0; x -= (x & (-x))) res += arr[x];
    return res;
  }
};
long long inversion_number(vector<int> &a) {
  BIT<int> bit(100);
  int n = a.size();
  long long res = 0;
  for (int i = n - 1; i >= 0; i--) {
    res += bit.sum(a[i] - 1);
    bit.add(a[i], 1);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<long long> d(n);
  for (int i = 0; i < n; i++) cin >> d[i];
  vector<pair<int, int>> ed(m);
  vector<vector<int>> ad(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    ed[i] = {a, b};
    ad[a].push_back(b);
    ad[b].push_back(a);
  }
  vector<int> ind(n);
  for (int i = 0; i < n; i++) ind[i] = i;
  sort(ind.begin(), ind.end(), [&](int i0, int i1) { return d[i0] < d[i1]; });
  if (d[ind[0]] != d[ind[1]]) {
    cout << -1 << "\n";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    bool bo2 = false;
    for (int ch : ad[i]) {
      if (d[ch] <= d[i]) {
        bo2 = true;
      }
    }
    if (!bo2) {
      cout << -1 << "\n";
      return 0;
    }
  }
  vector<int> c(n);
  c[ind[0]] = 1;
  c[ind[1]] = 2;
  vector<long long> dist(n);
  dist[ind[0]] = d[ind[0]];
  dist[ind[1]] = d[ind[1]];
  map<pair<int, int>, long long> mp;
  mp[{ind[0], ind[1]}] = d[ind[0]];
  mp[{ind[1], ind[0]}] = d[ind[1]];
  for (int i = 2; i < n; i++) {
    int cur = ind[i];
    int t = -1;
    for (int ch : ad[cur]) {
      if (c[ch] == 0) continue;
      if (dist[ch] > d[cur]) continue;
      t = ch;
    }
    if (t == -1) {
      cout << -1 << "\n";
      return 0;
    }
    dist[cur] = d[cur];
    c[cur] = 3 - c[t];
    for (int ch : ad[cur]) {
      if (ch != t) {
        mp[{cur, ch}] = 1000000000;
        mp[{ch, cur}] = 1000000000;
      } else {
        mp[{cur, ch}] = d[cur];
        mp[{ch, cur}] = d[cur];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (c[i] == 1)
      cout << "W";
    else
      cout << "B";
  }
  cout << "\n";
  for (int i = 0; i < m; i++) {
    cout << mp[ed[i]] << "\n";
  }
  return 0;
}
