#include <bits/stdc++.h>
using namespace std;
int n, m, uu, vv, d[100100], c[200100], co[100100];
vector<int> ga[100100];
vector<pair<int, int> > cand[100100];
pair<int, int> nxt[100100];
void search(int u) {
  int v = nxt[u].first;
  if (!co[v]) search(v);
  co[u] = 3 - co[v];
  c[nxt[u].second] = d[u];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> d[i];
  for (int i = 1; i <= m; i++) {
    cin >> uu >> vv;
    ga[uu].push_back(vv);
    ga[vv].push_back(uu);
    if (d[uu] >= d[vv]) cand[uu].push_back(make_pair(vv, i));
    if (d[vv] >= d[uu]) cand[vv].push_back(make_pair(uu, i));
  }
  for (int i = 1; i <= n; i++) {
    if (cand[i].size() == 0) {
      cout << -1 << endl;
      return 0;
    }
    nxt[i] = cand[i][0];
  }
  for (int i = 1; i <= n; i++) {
    int j = nxt[i].first;
    if (nxt[j].first == i) {
      c[nxt[i].second] = d[i];
      co[i] = 1;
      co[j] = 2;
    }
    search(i);
  }
  for (int i = 1; i <= n; i++) {
    if (co[i] == 1)
      cout << "W";
    else
      cout << "B";
  }
  cout << endl;
  for (int i = 1; i <= m; i++) {
    if (!c[i]) c[i] = 1e9;
    cout << c[i] << endl;
  }
  cout << endl;
  return 0;
}
