#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;
class XorShift {
  unsigned int x, y, z, w, t;

 public:
  XorShift() {
    x = 133553533;
    y = 314867339;
    z = 664298413;
    w = 999999937;
    t = 0;
  }
  unsigned int rand() {
    t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
    return w & 0x7fffffff;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  vector<pair<int, int>> v(N);
  vector<int> w(N);
  for (int i = 0; i < N; i++) {
    cin >> K;
    v[i] = {K, i};
    w[i] = K;
  }
  sort(v.begin(), v.end());
  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});
  }
  vector<int> weight(M);
  string color(N, 'a');
  bool flag = true;
  for (auto i : v) {
    int nn = -1;
    for (auto j : edge[i.second]) {
      if (i.first >= w[j.first]) nn = j.first;
    }
    if (nn == -1) {
      flag = false;
      cout << -1 << endl;
      return 0;
      break;
    }
    for (auto j : edge[i.second]) {
      if (i.first >= w[j.first]) {
        if (weight[j.second] == 0) {
          weight[j.second] = i.first;
        }
        if (color[i.second] == 'a') {
          if (color[j.first] == 'B')
            color[i.second] = 'W';
          else
            color[i.second] = 'B';
        }
      }
    }
  }
  cout << color << endl;
  for (auto i : weight) cout << i << endl;
  return 0;
}
