#include <bits/stdc++.h>
using namespace std;
const int M = 120000;
const int inf = 1e9;
int c[M] = {0};
pair<int, int> p[M];
vector<pair<int, int> > g[M];
int n, m, k;
int dd[M];
char s[M];
bool ok(int i) { return s[i] == 'W' || s[i] == 'B'; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  int u, v;
  for (int i = (1); i <= (n); ++i) {
    cin >> p[i].first;
    dd[i] = p[i].first;
    p[i].second = i;
  }
  sort(p + 1, p + 1 + n);
  for (int i = (1); i <= (m); ++i) {
    cin >> u >> v;
    g[u].push_back({v, i});
    g[v].push_back({u, i});
  }
  int flag = 1;
  for (int i = (1); i <= (n); ++i) {
    int id = p[i].second;
    if (ok(id)) continue;
    int d = p[i].first;
    bool done = 0;
    for (pair<int, int> to : g[id]) {
      if (ok(to.first)) {
        c[to.second] = d;
        s[id] = (s[to.first] == 'W' ? 'B' : 'W');
        done = 1;
        break;
      }
    }
    if (!done) {
      for (pair<int, int> to : g[id]) {
        if (dd[to.first] == d) {
          done = 1;
          s[id] = 'W';
          s[to.first] = 'B';
          c[to.second] = d;
        }
      }
    }
    if (!done) {
      flag = 0;
      break;
    }
  }
  if (flag) {
    s[n + 1] = '\0';
    cout << s + 1 << endl;
    for (int i = (1); i <= (m); ++i) {
      cout << (c[i] ? c[i] : inf) << endl;
    }
  } else
    cout << -1 << endl;
  return 0;
}
