#include <bits/stdc++.h>
using namespace std;
void g_dir(vector<vector<pair<long long, long long> > > &graph, long long a,
           long long b, long long w = 1) {
  graph[a].push_back(pair<long long, long long>(b, w));
}
void g_undir(vector<vector<pair<long long, long long> > > &graph, long long a,
             long long b, long long w = 1) {
  g_dir(graph, a, b, w);
  g_dir(graph, b, a, w);
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
  }
}
template <class T>
void chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
  }
}
const long long INF = 1000000000;
const long long MOD = 1000000007;
const long long NUM = 101010;
long long N, M;
long long D[101010];
vector<long long> path[101010];
map<long long, long long> w[101010];
long long ans[101010];
long long d[101010];
long long I1[202020], I2[202020];
int main() {
  cin >> N >> M;
  for (long long(i) = 1; (i) <= (N); (i)++) cin >> D[i];
  long long A = INF, B = INF, C = INF;
  for (long long(i) = 0; (i) < (M); (i)++) {
    long long a, b;
    cin >> a >> b;
    path[a].push_back(b);
    path[b].push_back(a);
    if (D[a] == D[b] && D[a] < C) {
      A = a;
      B = b;
      C = D[a];
    }
    I1[i] = a;
    I2[i] = b;
  }
  if (C == INF) {
    cout << -1 << endl;
    return 0;
  }
  queue<long long> Q;
  d[A] = 1;
  ans[A] = 1;
  Q.push(A);
  while (!Q.empty()) {
    long long idx = Q.front();
    Q.pop();
    for (long long(i) = 0; (i) < (path[idx].size()); (i)++) {
      long long to = path[idx][i];
      if (w[idx][to] > 0) continue;
      if (d[idx] == d[to]) {
        w[idx][to] = INF;
        w[to][idx] = INF;
        continue;
      }
      if (D[to] < D[idx]) {
        cout << -1 << endl;
        return 0;
      }
      d[to] = d[idx] + 1;
      ans[to] = 1;
      if (ans[idx] == 1) ans[to] = 2;
      w[idx][to] = D[to];
      w[to][idx] = D[to];
      Q.push(to);
    }
  }
  for (long long(i) = 1; (i) <= (N); (i)++) cout << (ans[i] == 1 ? "B" : "W");
  cout << endl;
  for (long long(i) = 0; (i) < (M); (i)++) {
    cout << w[I1[i]][I2[i]] << endl;
  }
  return 0;
}
