#include <bits/stdc++.h>
using namespace std;
void solve();
using ll = long long;
template <class T = ll>
using V = vector<T>;
using vi = V<int>;
using vl = V<>;
using vvi = V<V<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {
  IoSetupNya() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(7);
  }
} iosetupnya;
template <typename T, typename U>
inline bool amin(T &x, U y) {
  return (y < x) ? (x = y, true) : false;
}
template <typename T, typename U>
inline bool amax(T &x, U y) {
  return (x < y) ? (x = y, true) : false;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  int s = (int)v.size();
  for (long long i = 0; i < (long long)(s); i++) os << (i ? " " : "") << v[i];
  return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) is >> x;
  return is;
}
void in() {}
template <typename T, class... U>
void in(T &t, U &...u) {
  cin >> t;
  in(u...);
}
void out() { cout << "\n"; }
template <typename T, class... U>
void out(const T &t, const U &...u) {
  cout << t;
  if (sizeof...(u)) cout << " ";
  out(u...);
}
template <typename T>
void die(T x) {
  out(x);
  exit(0);
}
int main() { solve(); }
using P = pair<int, int>;
using vp = V<P>;
constexpr int MOD = 1000000007;
struct UF {
  vector<int> par, sizes;
  int cnt;
  UF(int N) : par(N), sizes(N, 1), cnt(N) {
    for (int i = 0; i < N; i++) par[i] = i;
  }
  int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return sizes[find(x)]; }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
    cnt--;
  }
  int count() const { return cnt; }
};
void solve() {
  int N, M;
  in(N, M);
  vi D(N);
  in(D);
  vi U(M), V(M);
  vvi g(N);
  for (long long i = 0; i < (long long)(M); i++) {
    in(U[i], V[i]);
    U[i]--, V[i]--;
    g[U[i]].push_back(V[i]);
    g[V[i]].push_back(U[i]);
  }
  map<P, int> m;
  for (long long i = 0; i < (long long)(N); i++) m[minmax(U[i], V[i])] = i;
  vi ord(N);
  iota((ord).begin(), (ord).end(), 0);
  sort((ord).begin(), (ord).end(), [&](int x, int y) { return D[x] < D[y]; });
  vi visited(N, -1);
  vi ans(M, 1000000000);
  for (auto &x : ord) {
    ;
    if (visited[x] != -1) continue;
    for (auto &dst : g[x]) {
      ;
      if (D[dst] > D[x]) continue;
      if (visited[dst] == -1)
        visited[dst] = 0, visited[x] = 1;
      else
        visited[x] = visited[dst] ^ 1;
      ans[m[minmax(x, dst)]] = D[x];
      ;
      break;
    }
    if (visited[x] == -1) die(-1);
  }
  for (long long i = 0; i < (long long)(N); i++)
    cout << (visited[i] == 0 ? 'B' : 'W');
  cout << "\n";
  for (auto &x : ans) out(x);
}
