#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1e9;
vector<long long> G[100010];
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > e(n);
  vector<long long> d(n);
  for (long long i = 0; i < n; i++) {
    cin >> d[i];
    e[i] = {d[i], i};
  }
  sort(e.begin(), e.end());
  map<pair<long long, long long>, long long> mp;
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].push_back(v);
    G[v].push_back(u);
    mp[{u, v}] = i;
    mp[{v, u}] = i;
  }
  vector<long long> color(n, -1);
  vector<long long> ans(m, INF);
  for (auto i : e) {
    long long u = i.second;
    for (auto v : G[u]) {
      if (d[v] == d[u]) {
        if (color[v] == -1) {
          color[v] = 0;
        }
        color[u] = (color[v] + 1) % 2;
        ans[mp[{u, v}]] = d[v];
        break;
      }
    }
    if (color[u] == -1) {
      for (auto v : G[u]) {
        if (color[v] != -1) {
          if (d[v] < d[u]) {
            color[u] = color[v];
            ans[mp[{u, v}]] = d[u] - d[v];
            break;
          }
        }
      }
    }
    if (color[u] == -1) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (long long i = 0; i < n; i++) {
    cout << (color[i] ? 'B' : 'W');
  }
  cout << endl;
  for (long long i = 0; i < m; i++) {
    cout << ans[i] << endl;
  }
}
