#include <bits/stdc++.h>
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
constexpr int inf = 1000000000;
int N, M;
int D[100000];
int color[100000];
int cost[200000];
std::vector<std::pair<int, int>> G[100000];
int main() {
  std::cin >> N >> M;
  for (int i = 0; i < (N); ++i) std::cin >> D[i];
  for (int i = 0; i < (M); ++i) {
    int u, v;
    std::cin >> u >> v;
    --u;
    --v;
    G[u].emplace_back(v, i);
    G[v].emplace_back(u, i);
  }
  for (int i = 0; i < (N); ++i) {
    bool flag = false;
    for (auto p : G[i]) {
      if (D[p.first] <= D[i]) {
        flag = true;
        break;
      }
    }
    if (!flag) {
      puts("-1");
      return 0;
    }
  }
  std::vector<int> order(N);
  std::iota(order.begin(), order.end(), 0);
  std::sort(order.begin(), order.end(), [](int x, int y) {
    if (D[x] == D[y]) return x < y;
    return D[x] < D[y];
  });
  for (int i = (1); i <= (N - 1); ++i) {
    int v = order[i];
    int pos = -1;
    for (int j = 0; j < (G[v].size()); ++j) {
      int u = G[v][j].first;
      if (D[u] < D[v]) {
        pos = j;
        break;
      }
    }
    if (pos == -1) {
      for (int j = 0; j < (G[v].size()); ++j) {
        int u = G[v][j].first;
        if (D[u] == D[v]) {
          pos = j;
          color[v] = 1 - color[u];
          cost[G[v][j].second] = D[v];
          break;
        }
      }
    } else {
      color[v] = color[G[v][pos].first];
      cost[G[v][pos].second] = D[v] - D[G[v][pos].first];
    }
    for (int j = 0; j < (G[v].size()); ++j) {
      if (j == pos) continue;
      cost[G[v][j].second] = inf;
    }
  }
  for (int i = 0; i < (N); ++i) {
    std::cout << (color[i] == 1 ? 'B' : 'W');
  }
  std::cout << '\n';
  for (int i = 0; i < (M); ++i) {
    std::cout << cost[i] << '\n';
  }
}
