#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long d[100005];
vector<pair<long long, long long> > G[100005];
vector<pair<long long, long long> > vec;
long long color[100005];
long long w[200005];
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    vec.push_back(pair<long long, long long>(d[i], i));
  }
  sort(vec.begin(), vec.end());
  long long u, v;
  for (int i = 1; i <= m; i++) {
    cin >> u >> v;
    G[u].push_back(pair<long long, long long>(v, i));
    G[v].push_back(pair<long long, long long>(u, i));
  }
  for (int i = 0; i < vec.size(); i++) {
    long long v = vec[i].second;
    bool flag = false;
    for (int j = 0; j < G[v].size(); j++) {
      long long u = G[v][j].first, e = G[v][j].second;
      if (d[u] > d[v]) continue;
      if (d[u] == d[v]) {
        if (color[u] == 0)
          color[u] = -1, color[v] = 1;
        else
          color[v] = -color[u];
        w[e] = d[v];
        flag = true;
        break;
      }
      if (d[u] < d[v]) {
        color[v] = color[u];
        w[e] = d[v] - d[u];
        flag = true;
        break;
      }
    }
    if (!flag) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (color[i] > 0)
      cout << "B";
    else
      cout << "W";
  }
  cout << endl;
  for (int i = 1; i <= m; i++) {
    if (w[i] == 0) w[i] = 1000000000;
    cout << w[i] << endl;
  }
  return 0;
}
