#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long int INF = (long long int)1e9;
struct Vertex {
  vector<pair<long long int, long long int> > node;
};
Vertex V[100005];
pair<long long int, long long int> D[100005];
long long int T[100005];
long long int C[200005];
long long int S[100005];
int main() {
  long long int N, M;
  cin >> N >> M;
  for (long long int(i) = (0); (i) < (N); ++(i)) {
    cin >> D[i].first;
    D[i].second = i;
    T[i] = D[i].first;
  }
  sort(D, D + N,
       [](pair<long long int, long long int> a,
          pair<long long int, long long int> b) { return a.first < b.first; });
  for (long long int(i) = (0); (i) < (M); ++(i)) {
    long long int a, b;
    cin >> a >> b;
    a--;
    b--;
    V[a].node.push_back(pair<long long int, long long int>(b, i));
    V[b].node.push_back(pair<long long int, long long int>(a, i));
  }
  if (D[0].first != D[1].first) {
    cout << -1 << endl;
    return 0;
  }
  memset(C, 0, sizeof(C));
  memset(S, -1, sizeof(S));
  for (long long int(i) = (0); (i) < (N); ++(i)) {
    long long int c = D[i].first;
    long long int v = D[i].second;
    bool exist = false;
    for (long long int(j) = (0); (j) < (V[v].node.size()); ++(j)) {
      long long int n = V[v].node[j].first;
      if (S[n] >= 0) {
        exist = true;
        C[V[v].node[j].second] = c;
        S[v] = (S[n] + 1) % 2;
        break;
      }
      if (S[n] == -1 && T[n] == c) {
        exist = true;
        C[V[v].node[j].second] = c;
        S[v] = 0;
        S[n] = 1;
        break;
      }
    }
    if (!exist) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (long long int(i) = (0); (i) < (M); ++(i)) {
    if (C[i] == 0) C[i] = INF;
  }
  for (long long int(i) = (0); (i) < (N); ++(i)) {
    if (S[i] == 0)
      cout << "B";
    else
      cout << "W";
  }
  cout << endl;
  for (long long int(i) = (0); (i) < (M); ++(i)) {
    cout << C[i] << endl;
  }
  return 0;
}
