#include <bits/stdc++.h>
using namespace std;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const long long MOD = 1000000007;
const int inf = 1 << 30;
const long long linf = 1LL << 60;
int n, m;
long long d[100000];
vector<pair<int, int> > e[100000];
string ans;
vector<int> anse;
bool cmp(const int& l, const int& r) { return d[l] < d[r]; }
bool cmp2(const pair<int, int>& l, const pair<int, int>& r) {
  return d[l.first] < d[r.first];
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < (int)n; i++) cin >> d[i];
  for (int i = 0; i < (int)n; i++) ans.push_back('B');
  anse.resize(m);
  for (int i = 0; i < (int)m; i++) anse[i] = -1;
  for (int i = 0; i < (int)m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    e[u].push_back(pair<int, int>(v, i));
    e[v].push_back(pair<int, int>(u, i));
  }
  for (int i = 0; i < (int)n; i++) sort(e[i].begin(), e[i].end(), cmp2);
  vector<int> ind(n);
  for (int i = 0; i < (int)n; i++) ind[i] = i;
  sort(ind.begin(), ind.end(), cmp);
  for (int _ = 0; _ < (int)n; _++) {
    int i = ind[_];
    if (d[e[i][0].first] > d[i]) {
      puts("-1");
      return 0;
    }
    bool fix = false;
    for (int j = 0; j < (int)e[i].size(); j++) {
      if (anse[e[i][j].second] != -1) {
        fix = true;
      }
    }
    for (int j = 0; j < (int)e[i].size(); j++) {
      int to = e[i][j].first;
      if (d[to] > d[i]) {
        break;
      }
      if (anse[e[i][j].second] != -1) continue;
      if (!fix) {
        if (ans[to] == 'B')
          ans[i] = 'W';
        else
          ans[i] = 'B';
        fix = true;
      }
      anse[e[i][j].second] = d[i];
    }
  }
  cout << ans << endl;
  for (int i = 0; i < (int)m; i++) cout << anse[i] << endl;
}
