#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T>
void chmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void chmax(T &a, T b) {
  a = max(a, b);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> d(n), c(n, -1);
  vector<P> v;
  vector<vector<P>> G(n);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    v.push_back(P(d[i], i));
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    G[a].push_back(P(b, i));
    G[b].push_back(P(a, i));
  }
  sort(v.begin(), v.end());
  int M = 1000000000;
  vector<int> res(m, M);
  for (int i = 0; i < n; i++) {
    int dd = v[i].first, id = v[i].second;
    bool f = false;
    int c0 = 0, c1 = 0, c2 = 0, c3 = 0;
    for (auto &e : G[i]) {
      int cc = res[e.second], to = e.first;
      if (d[to] < d[i]) {
        res[e.second] = d[i];
        if (c[to]) {
          c1++;
        } else {
          c0++;
        }
        f = true;
      } else if (d[to] == d[i]) {
        res[e.second] = d[i];
        if (c[to] != -1) {
          if (c[to]) {
            c3++;
          } else {
            c2++;
          }
        }
        f = true;
      }
    }
    if (c0 > 0 || c3 > 0) {
      c[i] = 0;
    } else {
      c[i] = 1;
    }
    if (!f) {
      cout << -1 << endl;
      return 0;
    }
    for (auto &e : G[i]) {
      int to = e.first;
      if (d[to] < d[i]) {
        if (c[i] == c[to]) {
          res[e.second] = d[i] - d[to];
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (c[i]) {
      cout << "B";
    } else {
      cout << "W";
    }
  }
  cout << endl;
  for (int i = 0; i < m; i++) {
    cout << res[i] << endl;
  }
}
