#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
int N, M;
map<int, vector<int>> mp;
int D[105000];
int ans[105000];
bool ok[105000];
vector<pair<int, int>> paths[105000];
struct UnionFind {
  vector<int> par;
  vector<int> rank;
  vector<long long> Size;
  UnionFind(int n = 1) { init(n); }
  void init(int n = 1) {
    par.resize(n + 1);
    rank.resize(n + 1);
    Size.resize(n + 1);
    for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      int r = root(par[x]);
      return par[x] = r;
    }
  }
  bool issame(int x, int y) { return root(x) == root(y); }
  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if ((x - 1) % N > (y - 1) % N) swap(x, y);
    if (rank[x] == rank[y]) ++rank[x];
    par[y] = x;
    Size[x] += Size[y];
    return true;
  }
  long long size(int x) { return Size[root(x)]; }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  for (int i = 1; i <= M; i++) {
    ans[i] = 1e9;
  }
  for (int i = 1; i <= N; i++) {
    cin >> D[i];
    mp[D[i]].push_back(i);
  }
  for (int i = 1; i <= M; i++) {
    int u, v;
    cin >> u >> v;
    paths[u].emplace_back(v, i);
    paths[v].emplace_back(u, i);
  }
  UnionFind uni(2 * (N + 1));
  for (auto tmp : mp) {
    int val = tmp.first;
    for (auto now : tmp.second) {
      if (ok[now]) continue;
      for (auto e : paths[now]) {
        int to = e.first;
        int edge = e.second;
        if (D[to] == D[now]) {
          ans[edge] = D[now];
          ok[now] = true;
          ok[to] = true;
          uni.merge(now, to + N);
          uni.merge(now + N, to);
          break;
        }
        if (D[to] < D[now]) {
          ans[edge] = D[now] - D[to];
          ok[now] = true;
          uni.merge(now, to);
          uni.merge(now + N, to + N);
          break;
        }
      }
      if (!ok[now]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 1; i <= N; i++) {
    if (uni.root(i) <= N)
      cout << "B";
    else
      cout << "W";
  }
  cout << endl;
  for (int i = 1; i <= M; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
