#include <bits/stdc++.h>
using namespace std;
void solve();
signed main() {
  clock_t beg = clock();
  cout << fixed << setprecision(15);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  long long tt = t;
  while (t--) {
    solve();
  }
  cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
  return 0;
}
long long n, m;
vector<pair<long long, long long>> by_d;
map<pair<long long, long long>, long long> idx;
const long long N = 1e5 + 55;
long long col[N];
long long d[N];
vector<long long> adj[N];
long long wt[N];
void solve() {
  cin >> n >> m;
  by_d.resize(n);
  for (long long i = 0; i < n; ++i) {
    cin >> d[i];
    by_d[i] = {d[i], i};
  }
  sort(by_d.begin(), by_d.end());
  for (long long i = 0; i < m; ++i) {
    long long u, v;
    cin >> u >> v;
    --u;
    --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    idx[{u, v}] = idx[{v, u}] = i;
  }
  fill(wt, wt + N, -1);
  for (long long i = 0; i < n; ++i) {
    col[i] = -1;
  }
  for (long long i = 0; i < n; ++i) {
    long long v = by_d[i].second;
    long long ref = -1;
    for (auto &j : adj[v]) {
      if (d[j] < d[v]) {
        ref = j;
        break;
      }
    }
    if (ref != -1) {
      col[v] = col[ref] ^ 1;
      wt[idx[{v, ref}]] = d[v] - d[ref];
      continue;
    }
    bool exist = false;
    for (auto &j : adj[v]) {
      if (d[j] == d[v]) {
        exist = true;
        if (col[j] != -1) {
          ref = j;
          break;
        }
      }
    }
    if (!exist) {
      cout << -1;
      return;
    }
    if (ref != -1) {
      col[v] = col[ref] ^ 1;
      wt[idx[{v, ref}]] = d[v];
    } else {
      col[v] = 0;
    }
  }
  for (long long i = 0; i < m; ++i) {
    if (wt[i] == -1) wt[i] = 1e9;
  }
  for (long long i = 0; i < n; ++i) {
    if (col[i] == 0)
      cout << "B";
    else
      cout << "W";
  }
  cout << '\n';
  for (long long i = 0; i < m; ++i) {
    cout << wt[i] << '\n';
  }
}
