#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 9;
vector<pair<int, int> > T[N];
int cost[N];
int col[N];
int d[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > dd(n);
  for (int i = 0; i < n; i++) {
    cin >> dd[i].first;
    d[i + 1] = dd[i].first;
    dd[i].second = i + 1;
  }
  sort(dd.begin(), dd.end());
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    T[u].push_back(make_pair(v, i));
    T[v].push_back(make_pair(u, i));
  }
  for (auto x : dd) {
    for (auto y : T[x.second]) {
      if (d[y.first] <= x.first) {
        cost[y.second] = x.first;
        col[x.second] = 1 - col[y.first];
        break;
      }
    }
  }
  bool answ;
  for (int i = 1; i <= n; i++) {
    answ = false;
    for (auto x : T[i]) {
      if (col[i] != col[x.first]) {
        if (cost[x.second] == d[i]) {
          answ = true;
        }
      }
    }
    if (!answ) {
      cout << "-1\n";
      return 0;
    }
  }
  for (int i = 1; i <= n; i++)
    if (col[i])
      cout << "W";
    else
      cout << "B";
  cout << "\n";
  for (int i = 0; i < m; i++) {
    if (cost[i] == 0) cost[i] = (int)1e9;
    cout << cost[i] << "\n";
  }
  return 0;
}
