#include <bits/stdc++.h>
using namespace std;
template <class A>
void pr(A a) {
  cout << a;
  cout << '\n';
}
template <class A, class B>
void pr(A a, B b) {
  cout << a << ' ';
  pr(b);
}
template <class A, class B, class C>
void pr(A a, B b, C c) {
  cout << a << ' ';
  pr(b, c);
}
template <class A, class B, class C, class D>
void pr(A a, B b, C c, D d) {
  cout << a << ' ';
  pr(b, c, d);
}
template <class A>
void PR(A a, long long n) {
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    if (i) cout << ' ';
    cout << a[i];
  }
  cout << '\n';
}
long long check(long long n, long long m, long long x, long long y) {
  return x >= 0 && x < n && y >= 0 && y < m;
}
const long long MAX = 1e9 + 7, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0},
                dy[4] = {0, 1, 0, -1};
void Main() {
  long long n, m;
  cin >> n >> m;
  pair<long long, long long> a[n];
  long long b[n];
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    cin >> a[i].first;
    a[i].second = i;
    b[i] = a[i].first;
  }
  vector<long long> v[n];
  pair<long long, long long> p[m];
  for (long long i = (long long)(0); i < (long long)(m); i++) {
    long long x, y;
    cin >> x >> y;
    x--, y--;
    v[x].push_back(y);
    v[y].push_back(x);
    p[i] = pair<long long, long long>(x, y);
  }
  sort(a, a + n);
  if (a[0].first != a[1].first) {
    pr(-1);
    return;
  }
  bool f = 0;
  for (long long i = (long long)(0); i < (long long)(v[a[0].second].size());
       i++) {
    if (v[a[0].second][i] == a[1].second) f = 1;
  }
  if (!f) {
    pr(-1);
    return;
  }
  long long u[n], d[n];
  memset(u, -1, sizeof(u));
  fill(d, d + n, MAX);
  map<pair<long long, long long>, long long> ma;
  set<long long> se;
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    int x = a[i].second, f = 0;
    for (long long j = (long long)(0); j < (long long)(v[x].size()); j++) {
      int y = v[x][j];
      if (se.count(y)) {
        f |= 1 << u[y];
        if (d[y] == MAX) {
          if (b[y] != b[x]) {
            pr(-1);
            return;
          } else
            d[y] = a[i].first;
        }
        ma[pair<long long, long long>(x, y)] =
            ma[pair<long long, long long>(y, x)] = a[i].first;
        d[x] = a[i].first;
      }
    }
    if (f & 1)
      f = 1;
    else
      f = 0;
    u[x] = f;
    se.insert(x);
  }
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    if (d[i] != b[i]) {
      pr(-1);
      return;
    }
  }
  string s = "";
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    if (u[i])
      s += 'W';
    else
      s += 'B';
  }
  pr(s);
  for (long long i = (long long)(0); i < (long long)(m); i++) pr(ma[p[i]]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  Main();
  return 0;
}
