#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long mod998 = 998244353;
const long long intmax = 2147483647;
const long long llmax = 9223372036854775807;
const char sp = ' ';
struct edge {
  int to, id;
};
int N, M, D[100000], dis[200000], col[100000], uf[100000];
vector<edge> e[100000];
priority_queue<pair<int, int>> pq;
int par(int x) {
  if (uf[x] == x) return x;
  return uf[x] = par(uf[x]);
}
void uni(int x, int y) {
  x = par(x);
  y = par(y);
  uf[y] = x;
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> D[i];
    pq.push({D[i], i});
    uf[i] = i;
    col[i] = -1;
  }
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    e[u].push_back({v, i});
    e[v].push_back({u, i});
    dis[i] = -1;
  }
  while (!pq.empty()) {
    int x = pq.top().second;
    pq.pop();
    bool f = false;
    for (edge E : e[x]) {
      if (D[E.to] == D[x]) {
        f = true;
        break;
      }
    }
    if (f) {
      for (int i = 0; i < e[x].size(); i++) {
        if (D[e[x][i].to] == D[x]) {
          if (col[par(e[x][i].to)] != -1) {
            col[par(x)] = (col[par(e[x][i].to)] ^ 1);
          } else {
            col[par(x)] = 1;
          }
          for (int j = 0; j < e[x].size(); j++) {
            if (D[e[x][j].to] == D[x]) {
              dis[e[x][j].id] = D[x];
            } else if (dis[e[x][j].id] == -1) {
              dis[e[x][j].id] = 1000000000;
            }
          }
          break;
        }
      }
    } else {
      for (int i = 0; i <= e[x].size(); i++) {
        if (i == e[x].size()) {
          cout << -1 << endl;
          return 0;
        }
        if (D[e[x][i].to] < D[x]) {
          for (int j = 0; j < e[x].size(); j++) {
            if (dis[e[x][j].id] == -1) {
              dis[e[x][j].id] = 1000000000;
            }
          }
          dis[e[x][i].id] = D[x] - D[e[x][i].to];
          uni(x, e[x][i].to);
          break;
        }
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << (col[par(i)] ? 'W' : 'B');
  }
  cout << endl;
  for (int i = 0; i < M; i++) {
    cout << dis[i] << endl;
  }
}
