#include <bits/stdc++.h>
using namespace std;
int A[200005];
int B[200005];
int D[100005];
pair<int, int> D2[100005];
vector<int> AdjList[100005];
char c[100005];
map<pair<int, int>, int> m;
int W[200005];
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      pq;
  for (int i = 1; i <= N; i++) {
    scanf("%d", &D[i]);
    pq.push(pair<int, int>(D[i], i));
  }
  set<pair<int, int> > s;
  for (int i = 1; i <= M; i++) {
    scanf("%d%d", &A[i], &B[i]);
    AdjList[A[i]].push_back(B[i]);
    AdjList[B[i]].push_back(A[i]);
    s.insert(pair<int, int>(A[i], B[i]));
    s.insert(pair<int, int>(B[i], A[i]));
    m[pair<int, int>(A[i], B[i])] = i;
    m[pair<int, int>(B[i], A[i])] = i;
  }
  for (int i = 1; i <= M; i++) {
    W[i] = 1000000000;
  }
  memset(c, 0, sizeof(c));
  while (!pq.empty()) {
    pair<int, int> temp = pq.top();
    pq.pop();
    int w = temp.first;
    int u = temp.second;
    if (c[u] == 0) {
      bool found = false;
      for (int v : AdjList[u]) {
        if (c[v] == 'W') {
          W[m[pair<int, int>(u, v)]] = w;
          c[u] = 'B';
          found = true;
          break;
        } else if (c[v] == 'B') {
          W[m[pair<int, int>(u, v)]] = w;
          c[u] = 'W';
          found = true;
          break;
        }
      }
      if (!found) {
        if (pq.empty()) {
          printf("-1");
          throw;
          return 0;
        }
        pair<int, int> temp = pq.top();
        int w2 = temp.first;
        int v = temp.second;
        if (w != w2) {
          printf("-1");
          throw;
          return 0;
        }
        pq.pop();
        c[u] = 'W';
        c[v] = 'B';
        W[m[pair<int, int>(u, v)]] = w;
      }
    } else {
      throw;
    }
  }
  for (int i = 1; i <= N; i++) {
    printf("%c", c[i]);
  }
  printf("\n");
  for (int i = 1; i <= M; i++) {
    printf("%d\n", W[i]);
  }
  return 0;
}
