#include <bits/stdc++.h>
using namespace std;
struct Comparator {
  int operator()(int l, int r) const { return r < l; }
};
struct Vec {
  double v[2];
  string to_s() { return "(" + to_string(v[0]) + "," + to_string(v[1]) + ")"; }
  double& operator[](int t) { return v[t]; }
  Vec operator+(Vec t) { return {v[0] + t[0], v[1] + t[1]}; }
  Vec& operator+=(Vec t) {
    v[0] += t[0];
    v[1] += t[1];
    return *this;
  }
  Vec operator-(Vec t) { return {v[0] - t[0], v[1] - t[1]}; }
  Vec& operator-=(Vec t) {
    v[0] -= t[0];
    v[1] -= t[1];
    return *this;
  }
  Vec operator*(double t) { return {v[0] * t, v[1] * t}; }
  Vec& operator*=(double t) {
    v[0] *= t;
    v[1] *= t;
    return *this;
  }
  double operator*(Vec t) { return v[0] * t[0] + v[1] * t[1]; }
  Vec operator-() { return {-v[0], -v[1]}; }
  static Vec Z;
};
Vec Vec::Z = {0, 0};
long long N, M;
vector<pair<long long, long long> > D;
vector<vector<long long> > G;
long long INF = 1000 * 1000 * 1000;
map<pair<long long, long long>, long long> en;
vector<bool> solved;
vector<long long> edges;
vector<bool> white;
vector<pair<long long, long long> > DO;
pair<long long, long long> to_e(long long s, long long t) {
  return {min(s, t), max(s, t)};
}
void no() {
  cout << -1 << endl;
  exit(0);
}
int main() {
  cin >> N >> M;
  solved.resize(N, false);
  D.resize(N);
  edges.resize(M, INF);
  white.resize(N, false);
  for (int(i) = 0; (i) < (N); ++(i)) {
    cin >> D[i].first;
    D[i].second = i;
  }
  G.resize(N);
  for (int(i) = 0; (i) < (M); ++(i)) {
    long long u, v;
    cin >> u >> v;
    --u;
    --v;
    if (u > v) swap(u, v);
    en[{u, v}] = i;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  DO = D;
  sort(begin(D), end(D));
  for (int i = 0; i < D.size(); ++i) {
    pair<long long, long long> p = D[i];
    if (solved[p.second]) continue;
    bool s = false;
    for (long long n : G[p.second]) {
      if (solved[n]) {
        white[p.second] = !white[n];
        solved[p.second] = true;
        edges[en[to_e(p.second, n)]] = p.first;
        s = true;
        break;
      }
    }
    if (!s) {
      bool t = false;
      for (long long n : G[p.second]) {
        if (p.first == DO[n].first) {
          solved[p.second] = solved[n] = true;
          edges[en[to_e(p.second, n)]] = p.first;
          t = true;
        }
      }
      if (!t) no();
    }
  }
  for (int(i) = 0; (i) < (N); ++(i)) cout << ((white[i]) ? "W" : "B");
  cout << endl;
  for (int(i) = 0; (i) < (M); ++(i)) cout << edges[i] << endl;
  return 0;
}
