#include <bits/stdc++.h>
using namespace std;
constexpr long long int MOD = 1000000007;
constexpr long double EPS = 1e-12;
long long int N, M, K, H, W, L, R;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  vector<pair<int, pair<int, int>>> v(N);
  vector<int> w(N);
  for (int i = 0; i < N; i++) {
    cin >> K;
    v[i] = {(int)K, {1000000000, i}};
    w[i] = K;
  }
  vector<set<pair<int, int>>> edge(N);
  for (int i = 0; i < M; i++) {
    cin >> L >> R;
    L--, R--;
    edge[L].insert({R, i});
    edge[R].insert({L, i});
  }
  for (int i = 0; i < N; i++) {
    for (auto j : edge[i]) {
      v[i].second.first = min(v[i].second.first, w[j.first]);
    }
  }
  sort(v.begin(), v.end());
  vector<int> weight(M);
  string color(N, 'a');
  bool flag = true;
  for (auto i : v) {
    int nn = -1;
    if (i.second.first > i.first) {
      cout << -1 << endl;
      return 0;
    }
    int skip = -1;
    for (auto j : edge[i.second.second]) {
      if (w[j.first] == i.second.first) {
        skip = j.first;
        if (w[j.first] < i.first) {
          color[i.second.second] = color[j.first];
          weight[j.second] = i.first - w[j.first];
        } else {
          if (color[j.first] == 'B')
            color[i.second.second] = 'W';
          else
            color[i.second.second] = 'B';
          weight[j.second] = i.first;
        }
        break;
      }
    }
    for (auto j : edge[i.second.second]) {
      if (j.first == skip) continue;
      if (weight[j.second]) continue;
      if (w[j.first] > i.first) continue;
      weight[j.second] = i.first;
    }
  }
  cout << color << endl;
  for (auto i : weight) cout << i << endl;
  return 0;
}
