#include <bits/stdc++.h>
using namespace std;
long long mod(long long a) {
  long long c = a % (long long)(1E9 + 7);
  if (c >= 0) return c;
  return c + (long long)(1E9 + 7);
}
long long inf = (long long)1E16;
long long max(long long a, long long b) {
  if (a < b)
    return b;
  else
    return a;
}
long long min(long long a, long long b) {
  if (a > b)
    return b;
  else
    return a;
}
void Max(long long &pos, long long val) { pos = max(pos, val); }
void Min(long long &pos, long long val) { pos = min(pos, val); }
void Add(long long &pos, long long val) { pos = mod(pos + val); }
long double EPS = 1E-9;
struct edge {
  long long to;
  long long num;
};
pair<long long, long long> d[200005];
long long revd[200005];
bool comp(edge a, edge b) { return revd[a.to] < revd[b.to]; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  inf = (long long)1E9;
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i <= n - 1; i++) {
    cin >> d[i].first;
    d[i].second = i + 1;
  }
  vector<edge> v[n + 1];
  for (long long i = 1; i <= m; i++) {
    long long a, b;
    cin >> a >> b;
    edge e = {b, i};
    v[a].push_back(e);
    e.to = a;
    v[b].push_back(e);
  }
  long long ans[m + 1];
  for (long long i = 1; i <= m; i++) ans[i] = inf;
  sort(d, d + n);
  for (long long i = 0; i <= n - 1; i++) {
    revd[d[i].second] = i;
  }
  for (long long i = 1; i <= n; i++) {
    sort(v[i].begin(), v[i].end(), comp);
  }
  long long mini[n + 1];
  for (long long i = 1; i <= n; i++) mini[i] = inf;
  vector<long long> gra[n + 1];
  for (long long i = 0; i <= n - 1; i++) {
    long long ver = d[i].second;
    long long nex = v[ver][0].to;
    ans[v[ver][0].num] = d[i].first;
    if (mini[ver] < d[i].first) {
      cout << -1 << endl;
      return 0;
    }
    mini[ver] = d[i].first;
    Min(mini[nex], d[i].first);
    gra[ver].push_back(nex);
    gra[nex].push_back(ver);
  }
  long long col[n + 1];
  memset(col, -1, sizeof(col));
  queue<long long> q;
  q.push(1);
  col[1] = 1;
  while (!q.empty()) {
    long long t = q.front();
    q.pop();
    for (auto x : gra[t]) {
      if (col[x] != -1) continue;
      col[x] = 3 - col[t];
      q.push(x);
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (col[i] == 1)
      cout << "B";
    else
      cout << "W";
  }
  cout << endl;
  for (long long i = 1; i <= m; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
