#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v[100009];
int ans[200009], d[100009];
bool cl[100009];
pair<int, int> p[100009];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int inf = 1000000000;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    p[i] = make_pair(d[i], i);
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(make_pair(b, i));
    v[b].push_back(make_pair(a, i));
    ans[i] = inf;
  }
  sort(p + 1, p + n + 1);
  for (int i = 1; i <= n; i++) {
    int hn = p[i].second, c = p[i].first;
    bool f = false;
    for (int j = 0; j < v[hn].size(); j++) {
      int tn = v[hn][j].first, ti = v[hn][j].second;
      if (d[tn] > c) continue;
      ans[ti] = c;
      cl[i] = !cl[tn];
      f = true;
      break;
    }
    if (!f) {
      cout << -1 << '\n';
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (cl[i])
      cout << "B";
    else
      cout << "W";
  }
  cout << '\n';
  for (int i = 1; i <= m; i++) cout << ans[i] << '\n';
  return 0;
}
