#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 << 18;
int d[MAX];
vector<pair<int, int> > g[MAX];
char s[MAX];
int c[MAX];
bool cmp(int u, int v) { return d[u] != d[v] ? d[u] < d[v] : u < v; }
bool cmp2(pair<int, int> u, pair<int, int> v) { return cmp(u.first, v.first); }
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];
  }
  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;
  }
  for (int i = (0); i < (n); ++i) {
    sort(g[i].begin(), g[i].end(), cmp2);
    pair<int, int> to = g[i][0];
    if (cmp(to.first, i)) {
      c[to.second] = d[i];
      if (s[to.first] == 'W') s[i] = 'B';
    } else if (d[to.first] > d[i]) {
      cout << "-1\n";
      return 0;
    }
  }
  for (int i = (0); i < (n); ++i) {
    int mn = INF;
    for (pair<int, int> to : g[i]) {
      if (s[i] != s[to.first]) mn = min(mn, c[to.second]);
    }
    assert(mn == d[i]);
  }
  cout << s << "\n";
  for (int i = (0); i < (m); ++i) cout << c[i] << "\n";
  return 0;
}
