#include <bits/stdc++.h>
using namespace std;
long long int INF = 1e18;
long long int MOD = 1e9 + 7;
long long int D[110000];
int memo[110000];
vector<pair<long long int, long long int> > E[110000];
long long int ans[210000];
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<long long int, long long int> > v;
  for (int i = 1; i <= N; i++) {
    cin >> D[i];
    v.push_back(pair<long long int, long long int>(D[i], i));
  }
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    E[u].push_back(pair<long long int, long long int>(v, i));
    E[v].push_back(pair<long long int, long long int>(u, i));
  }
  sort(v.begin(), v.end());
  for (pair<long long int, long long int> p : v) {
    int pos = p.second;
    int les;
    pair<long long int, long long int> e;
    bool flag = true;
    for (pair<long long int, long long int> ed : E[pos]) {
      int to = ed.first;
      if (D[to] <= D[pos]) {
        flag = false;
        les = to;
        e = ed;
      }
    }
    if (flag) {
      cout << -1 << endl;
      return 0;
    }
    if (memo[les] <= 0) {
      memo[pos] = 1;
    } else {
      memo[pos] = -1;
    }
    ans[e.second] = D[pos];
  }
  for (int i = 1; i <= N; i++) {
    if (memo[i] == 1) {
      cout << "B";
    } else {
      cout << "W";
    }
  }
  cout << endl;
  for (int i = 0; i < M; i++) {
    if (ans[i] == 0) {
      cout << (int)1e9 << endl;
    } else {
      cout << ans[i] << endl;
    }
  }
  return 0;
}
