#include <bits/stdc++.h>
using namespace std;
using VP = vector<pair<long long, long long> >;
using VVP = vector<VP>;
using VI = vector<long long>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const long long INF = 1LL << 61;
const long long mod = 1e9 + 7;
int main() {
  int i, j;
  int n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > d(n);
  VI dd(n);
  vector<vector<pair<long long, long long> > > E(n);
  VI c(n, 0);
  VI h(m, -1);
  int x;
  for (i = 0; i < n; i++) {
    cin >> x;
    d[i] = pair<long long, long long>(x, i);
    dd[i] = x;
  }
  sort(d.begin(), d.end());
  int u, v;
  for (i = 0; i < m; i++) {
    cin >> u >> v;
    u--;
    v--;
    E[u].push_back(pair<long long, long long>(v, i));
    E[v].push_back(pair<long long, long long>(u, i));
  }
  for (i = 0; i < n; i++) {
    int s = d[i].second;
    bool ng = 1;
    for (pair<long long, long long> t : E[s]) {
      if (dd[t.first] <= dd[s]) {
        if (c[s] == 0 && c[t.first] != 0)
          c[s] = -c[t.first];
        else if (c[s] == 0)
          c[s] = 1;
        h[t.second] = dd[s];
        ng = 0;
      }
    }
    if (ng) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (i = 0; i < n; i++) {
    if (c[i] == -1)
      cout << "B";
    else
      cout << "W";
  }
  cout << endl;
  for (i = 0; i < m; i++) {
    cout << h[i] << endl;
  }
  return 0;
}
