#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> d(n);
  vector<vector<pair<int, int>>> edges(n);
  vector<int> c(n, -1), w(m, 1e9);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &d[i].first);
    d[i].second = i;
  }
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    edges[u].push_back(pair<int, int>(v, i));
    edges[v].push_back(pair<int, int>(u, i));
  }
  sort(d.begin(), d.end());
  for (int i = 0; i < n; ++i) {
    bool ok = false;
    for (pair<int, int>& p : edges[d[i].second]) {
      if (d[p.first].first <= d[i].first) {
        ok = true;
        if (c[d[i].second] < 0) {
          if (c[p.first] < 0) {
            c[d[i].second] = 0;
            c[p.first] = 1;
          } else {
            c[d[i].second] = (1 ^ c[p.first]);
          }
        }
        w[p.second] = d[i].first;
        break;
      }
    }
    if (ok == false) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; ++i) cout << (c[i] ? "B" : "W");
  cout << endl;
  for (int i = 0; i < m; ++i) cout << w[i] << "\n";
}
