#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;
  vector<pair<long long, long long> > v;
  for (long long(i) = 1; (i) <= (N); (i)++) {
    cin >> D[i];
    v.push_back(pair<long long, long long>(D[i], i));
  }
  sort(v.begin(), v.end());
  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);
    I1[i] = a;
    I2[i] = b;
  }
  for (long long(i) = 0; (i) < (N); (i)++) {
    long long idx = v[i].second;
    long long f = 0;
    long long c1 = 0, c2 = 0;
    for (long long(j) = 0; (j) < (path[idx].size()); (j)++) {
      long long to = path[idx][j];
      if (ans[to] == 1) {
        f = 1;
        c1++;
      }
      if (ans[to] == 2) {
        f = 1;
        c2++;
      }
    }
    if (f == 0) {
      d[idx] = D[idx];
      ans[idx] = 1;
    } else {
      ans[idx] = 1;
      if (c2 == 0) ans[idx] = 2;
      for (long long(j) = 0; (j) < (path[idx].size()); (j)++) {
        long long to = path[idx][j];
        if (ans[to] == 0) continue;
        if (d[to] == D[idx]) d[to] = 0;
        w[idx][to] = D[idx];
        w[to][idx] = D[idx];
      }
    }
  }
  for (long long(i) = 1; (i) <= (N); (i)++) {
    if (d[i] > 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  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;
}
