#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000;
const long long LINF = (long long)INF * INF;
const int MAX = 1 << 17;
int d[MAX];
vector<pair<int, int> > g[MAX];
char s[MAX];
int ver[MAX];
int c[MAX];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = (0); i < (n); ++i) {
    s[i] = 'W';
    cin >> d[i];
    ver[i] = i;
  }
  s[n] = '\0';
  for (int i = (0); i < (m); ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(make_pair(v, i));
    g[v].push_back(make_pair(u, i));
    c[i] = INF;
  }
  sort(ver, ver + n, [](int u, int v) { return d[u] < d[v]; });
  for (int i = (0); i < (n); ++i) {
    bool ok = false;
    for (pair<int, int> to : g[ver[i]]) {
      if (d[to.first] <= d[ver[i]]) {
        c[to.second] = d[ver[i]];
        ok = true;
        if (s[to.first] == 'W') s[ver[i]] = 'B';
        break;
      }
    }
    if (!ok) {
      cout << "-1\n";
      return 0;
    }
  }
  cout << s << "\n";
  for (int i = (0); i < (m); ++i) cout << c[i] << "\n";
  return 0;
}
