#include <bits/stdc++.h>
using namespace std;
using uint = uint32_t;
using LL = int64_t;
using ULL = uint64_t;
using PP = pair<LL, LL>;
template <typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) {
  return ist >> right.first >> right.second;
}
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) {
  return ost << right.first << ' ' << right.second;
}
template <class T, class TCompatible, size_t N>
void Fill(T (&dest)[N], const TCompatible& val) {
  fill(dest, dest + N, val);
}
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T (&dest)[M][N], const TCompatible& val) {
  for (int i = 0; i < M; ++i) Fill(dest[i], val);
}
template <class T>
T Next() {
  T buf;
  cin >> buf;
  return buf;
}
istream& Ignore(istream& ist) {
  string s;
  ist >> s;
  return ist;
}
bool Inside(int i, int j, int h, int w) {
  return i >= 0 && i < h && j >= 0 && j < w;
}
istream& operator>>(istream& ist, __int128& val) {
  LL tmp;
  ist >> tmp;
  val = tmp;
  return ist;
}
ostream& operator<<(ostream& ost, __int128 val) {
  LL tmp = val;
  ost << tmp;
  return ost;
}
const int MAX = 1000000000;
int N, M;
int D[100000];
vector<PP> G[100000];
int ans[200000];
int check[200000];
void solve() {
  Fill(ans, MAX);
  Fill(check, MAX);
  PriorityQ<PP> Q;
  for (LL i = (0), i_max_ = (N); i < i_max_; ++i) {
    Q.push(PP(D[i], i));
  }
  vector<bool> used(N);
  vector<int> color(N);
  while (!Q.empty()) {
    auto p = Q.top();
    Q.pop();
    int d = p.first;
    int from = p.second;
    used[from] = true;
    for (PP e : G[from]) {
      int to = e.first;
      int id = e.second;
      if (used[to]) {
        ans[id] = d;
        color[from] = !color[to];
        break;
      }
    }
  }
  for (LL from = (0), from_max_ = (N); from < from_max_; ++from) {
    for (PP e : G[from]) {
      int to = e.first;
      if (color[from] == color[to]) continue;
      int id = e.second;
      check[from] = min(check[from], ans[id]);
    }
    if (check[from] != D[from]) {
      cout << -1 << endl;
      return;
    }
  }
  for (LL i = (0), i_max_ = (N); i < i_max_; ++i) {
    cout << (color[i] ? 'B' : 'W');
  }
  cout << endl;
  for (LL j = (0), j_max_ = (M); j < j_max_; ++j) {
    cout << ans[j] << endl;
  }
}
int main() {
  cin >> N >> M;
  for (LL i = (0), i_max_ = (N); i < i_max_; ++i) cin >> D[i];
  for (LL j = (0), j_max_ = (M); j < j_max_; ++j) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    G[a].push_back(PP(b, j));
    G[b].push_back(PP(a, j));
  }
  solve();
  return 0;
}
