#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T1, class T2>
ostream& operator<<(ostream& s, pair<T1, T2> P) {
  return s << '<' << P.first << ", " << P.second << '>';
}
template <class T>
ostream& operator<<(ostream& s, vector<T> P) {
  for (int i = 0; i < P.size(); ++i) {
    if (i > 0) {
      s << " ";
    }
    s << P[i];
  }
  return s;
}
template <class T>
ostream& operator<<(ostream& s, vector<vector<T>> P) {
  for (int i = 0; i < P.size(); ++i) {
    s << endl << P[i];
  }
  return s << endl;
}
template <class T>
ostream& operator<<(ostream& s, set<T> P) {
  for (auto it : P) {
    s << "<" << it << "> ";
  }
  return s << endl;
}
template <class T1, class T2>
ostream& operator<<(ostream& s, map<T1, T2> P) {
  for (auto it : P) {
    s << "<" << it.first << "->" << it.second << "> ";
  }
  return s << endl;
}
const int INF = 1000000000;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
int N, M;
Graph G;
vector<long long> D;
void solve() {
  map<int, vector<int>> as;
  for (int i = 0; i < N; ++i) as[D[i]].push_back(i);
  vector<int> color(N, -1);
  vector<int> res(M, INF);
  set<int> less;
  for (auto it : as) {
    int d = it.first;
    auto vec = it.second;
    for (auto v : vec) less.insert(v);
    for (auto v : vec) {
      if (color[v] != -1) continue;
      for (auto e : G[v]) {
        if (less.count(e.first)) {
          res[e.second] = d;
          if (color[e.first] != -1)
            color[v] = 1 - color[e.first];
          else
            color[v] = 1;
          break;
        }
      }
      if (color[v] == -1) {
        cout << -1 << endl;
        return;
      }
    }
  }
  for (int v = 0; v < N; ++v) {
    if (color[v] == 1)
      cout << 'B';
    else
      cout << 'W';
  }
  cout << endl;
  for (int i = 0; i < M; ++i) cout << res[i] << endl;
}
int main() {
  while (cin >> N >> M) {
    D.resize(N);
    for (int i = 0; i < N; ++i) cin >> D[i];
    G.assign(N, vector<Edge>());
    for (int i = 0; i < M; ++i) {
      int u, v;
      cin >> u >> v;
      --u, --v;
      G[u].emplace_back(v, i);
      G[v].emplace_back(u, i);
    }
    solve();
  }
}
