#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void maximize(T &a, T b) {
  a = max(a, b);
}
template <typename T>
inline void minimize(T &a, T b) {
  a = min(a, b);
}
template <typename T>
inline bool middle(T a, T b, T c) {
  return b <= a && a <= c;
}
template <class T>
inline bool MX(T &l, const T &r) {
  return l < r ? l = r, 1 : 0;
}
template <class T>
inline bool MN(T &l, const T &r) {
  return l > r ? l = r, 1 : 0;
}
inline void outputVI(vector<long long> x) {
  for (long long i = (0LL); i < (long long)((long long(x.size()))); i++) {
    cout << ((i) ? (" ") : ("")) << x[i];
  }
  cout << ("") << endl;
}
const long long SIZE1 = 5e5 + 1000;
const long long SIZE2 = 5010;
const long long SIZE3 = 430;
const long long SIZE = SIZE1;
const long long MAPSIZE = 40;
const long long p998 = 998244353;
const long long p107 = 1000000007;
const long long p = p107;
const long long INF = 1000000000;
const long double EPS = 1e-7;
const long long NONE = -2;
long long N, M, K, Q, H, W;
vector<pair<long long, long long> > edges[SIZE];
long long vals[SIZE], answer = 0LL;
long long A[SIZE], B[SIZE], C[SIZE];
long long D[SIZE];
bool used[SIZE];
long long colors[SIZE];
long long ans[SIZE];
long long color(long long x) {
  long long mins = INF + 1;
  for (auto nexts : edges[x]) {
    long long next = nexts.first;
    if (D[next] <= D[x] and colors[next]) {
      colors[x] = 3 - colors[next];
    }
    MN(mins, D[next]);
  }
  if (mins > D[x]) return 1;
  if (colors[x]) return 0;
  colors[x] = 1;
  for (auto nexts : edges[x]) {
    long long next = nexts.first;
    if (D[next] == D[x] and colors[next] == 0) {
      color(next);
    }
  }
  return 0;
}
long long solve() {
  cin >> N >> M;
  vector<pair<long long, long long> > v;
  for (long long i = (0LL); i < (long long)(N); i++) {
    cin >> D[i];
    v.emplace_back(D[i], i);
  }
  for (long long i = (0LL); i < (long long)(M); i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].emplace_back(b, i);
    edges[b].emplace_back(a, i);
  }
  sort(v.begin(), v.end());
  for (long long i = (0LL); i < (long long)(v.size()); i++) {
    long long now = v[i].second;
    if (color(now)) return -1;
    for (auto nexts : edges[now]) {
      long long next = nexts.first;
      if (D[next] > D[now]) continue;
      if (colors[next] == colors[now])
        A[nexts.second] = INF;
      else
        A[nexts.second] = max(D[next], D[now]);
    }
  }
  for (long long i = (0LL); i < (long long)(N); i++) {
    ans[i] = INF;
    for (auto nexts : edges[i]) {
      long long next = nexts.first;
      if (colors[next] == colors[i]) assert(A[nexts.second] == INF);
      if (colors[next] != colors[i]) MN(ans[i], A[nexts.second]);
    }
    assert(ans[i] == D[i]);
  }
  string ss = "0BW";
  for (long long i = (0LL); i < (long long)(N); i++) {
    cout << ss[colors[i]];
  }
  cout << "\n";
  for (long long i = (0LL); i < (long long)(M); i++) {
    cout << A[i] << "\n";
  }
  return NONE;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  long long T = 1;
  for (long long i = (0LL); i < (long long)(T); i++) {
    long long ans = solve();
    if (ans == NONE) {
    } else {
      cout << ans << "\n";
    };
  }
  return 0;
}
