#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const int mod = 1000000007;
const long long int inf = 2.19e15 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-10;
template <class T, class U>
bool chmin(T& a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U>
bool chmax(T& a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
long long int gcd(long long int a, long long int b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  if (a == 0) {
    return b;
  }
  return a / gcd(a, b) * b;
}
template <class T>
void SO(T& ve) {
  sort(ve.begin(), ve.end());
}
template <class T>
void REV(T& ve) {
  reverse(ve.begin(), ve.end());
}
template <class T>
long long int LBI(const vector<T>& ar, T in) {
  return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T>
long long int UBI(const vector<T>& ar, T in) {
  return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}
int main(void) {
  int n, m, i, j;
  cin >> n >> m;
  vector<int> D(n);
  vector<pair<int, int>> sD(n);
  for (i = 0; i < n; i++) {
    cin >> D[i];
    sD[i] = make_pair(D[i], i);
  }
  SO(sD);
  vector<vector<pair<int, int>>> go(n);
  vector<int> ans(m, 1000000000);
  string S(n, 'W');
  for (i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    go[a].push_back(make_pair(b, i));
    go[b].push_back(make_pair(a, i));
  }
  for (i = 0; i < n; i++) {
    int t = sD[i].second;
    bool ok = false;
    for (auto it : go[t]) {
      int u = it.first;
      if (D[u] <= D[t]) {
        if (S[u] == 'W') {
          S[t] = 'B';
        } else {
          S[t] = 'W';
        }
        ans[it.second] = D[t];
        ok = true;
        break;
      }
    }
    if (!ok) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << S << endl;
  for (i = 0; i < m; i++) {
    cout << ans[i] << endl;
  }
}
