#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
long long mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
long long llmax = 9223372036854775807;
long long llmin = -9223372036854775807;
int iinf = intmax / 8;
long long inf = llmax / 8;
double eps = 1e-12;
struct edge {
  long long to, cost, num;
};
int V;
vector<edge> G[1000000];
long long d[1000000];
void addedge(int st, int ed, long long co, long long num) {
  edge e;
  e.to = ed;
  e.cost = co;
  e.num = num;
  G[st].push_back(e);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  pair<long long, long long> D[N];
  long long minnum = inf;
  long long dbase[N];
  for (long long i = (long long)0; i < (long long)N; i++) {
    long long d;
    cin >> d;
    dbase[i] = d;
    D[i] = pair<long long, long long>(d, i);
    minnum = min(minnum, d);
  }
  V = N;
  bool ok = false;
  for (long long i = (long long)0; i < (long long)M; i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    addedge(u, v, 1, i);
    addedge(v, u, 1, i);
    if (D[u].first == minnum && D[v].first == minnum) {
      ok = true;
    }
  }
  long long mark[N];
  fill(mark, mark + N, -1);
  long long wt[M];
  sort(D, D + N);
  mark[D[0].second] = 0;
  for (long long i = (long long)1; i < (long long)N; i++) {
    bool subok = false;
    long long from = D[i].second;
    for (long long j = (long long)0; j < (long long)G[from].size(); j++) {
      edge e = G[from][j];
      if (dbase[e.to] <= D[i].first) {
        subok = true;
        if (mark[from] == -1) {
          if (mark[e.to] == -1) {
            mark[from] = 0;
            mark[e.to] = 1;
          } else {
            mark[from] = 1 - mark[e.to];
          }
        }
        wt[e.num] = D[i].first;
      }
    }
    if (!subok) {
      ok = false;
      break;
    }
  }
  if (!ok) {
    cout << -1 << endl;
  } else {
    string S = "";
    for (long long i = (long long)0; i < (long long)N; i++) {
      if (mark[i] == 0) {
        S += "B";
      } else {
        S += "W";
      }
    }
    cout << S << endl;
    for (long long i = (long long)0; i < (long long)M; i++) {
      cout << wt[i] << endl;
    }
  }
}
