#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for (int i = 0; i < (int)vec.size(); i++)
    os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
  os << "}";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  for (auto &&itr : map_var) {
    os << *itr;
    itr++;
    if (itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  for (auto &&itr : set_var) {
    os << *itr;
    itr++;
    if (itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
void dump_func() { cerr << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
  cerr << head;
  if (sizeof...(Tail) > 0) cerr << ", ";
  dump_func(std::move(tail)...);
}
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
using vec = std::vector<T>;
template <class T>
void print(const T &x) {
  cout << x << "\n";
}
const long long MOD = 1000000007, INF0 = 1061109567, INF = INF0 * INF0;
const double EPS = 1e-10, PI = acos(-1.0);
const long long dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
long long d[200100];
long long flg[200100];
struct edge {
  long long from, to, index;
};
vec<edge> G[200100];
vec<edge> E;
long long cost[200100];
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  long long N, M;
  cin >> N >> M;
  map<long long, vec<long long>> ma;
  vec<pair<long long, long long>> lis;
  for (long long i = 0; i < N; i++) cin >> d[i], ma[d[i]].push_back(i);
  fill(cost, cost + M, 1000000000);
  for (long long i = 0; i < M; i++) {
    long long p, q;
    cin >> p >> q;
    p--;
    q--;
    G[p].push_back(edge{p, q, i});
    G[q].push_back(edge{q, p, i});
    E.push_back(edge{p, q, i});
    E.push_back(edge{q, p, i});
  }
  bool init = true;
  for (auto &&e : ma) {
    long long val = e.first;
    vec<long long> p = e.second;
    if (init) {
      for (auto &&e : p) {
        if (flg[e] == 0) {
          flg[e] = 1;
        };
        long long ret = 3 - flg[e];
        bool ok = true;
        for (auto &&e2 : G[e]) {
          ;
          if (flg[e2.to] != ret) {
          } else {
            ok = true;
            flg[e2.to] = ret;
            cost[e2.index] = val;
          }
        }
        if (!ok) {
          print(-1);
          return 0;
        }
      }
    }
  }
  for (long long i = 0; i < N; i++) {
    if (flg[i] == 1) {
      cout << 'B';
    } else {
      cout << 'W';
    }
  }
  cout << "\n";
  for (long long i = 0; i < M; i++) {
    print(cost[i]);
  }
}
