#include <bits/stdc++.h>
template <typename T>
T gcd(T a, T b) {
  return ((a % b == 0) ? b : gcd(b, a % b));
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;
namespace Problem {
using namespace std;
class Solver2 {
 public:
  int n, m;
  vector<int> d, c, neighbor;
  vector<map<int, pair<int, int>>> t;
  Solver2(LL n, LL m) : n(n), m(m), d(n), c(n, -1), neighbor(n, -1), t(n){};
  void solve() {
    for (int i = 0; i < n; ++i) {
      cin >> d[i];
    }
    for (int i = 0; i < m; ++i) {
      int u, v;
      cin >> u >> v;
      t[--u][--v] = {1e9, i};
      t[v][u] = {1e9, i};
    }
    vector<int> local_min;
    for (int i = 0; i < n; ++i) {
      bool is_min = true;
      for (auto v : t[i]) {
        if (d[i] > d[v.first]) is_min = false;
      }
      if (is_min) local_min.push_back(i);
    }
    bool ok = true;
    for (auto u : local_min) {
      bool ok_tmp = false;
      for (auto v : t[u]) {
        if (d[v.first] == d[u]) {
          neighbor[u] = v.first;
          ok_tmp = true;
        }
      }
      ok &= ok_tmp;
    }
    if (!ok) {
      cout << -1 << endl;
      return;
    }
    for (auto v : local_min) {
      if (c[v] >= 0) continue;
      int tmpc = c[neighbor[v]];
      if (tmpc < 0) {
        c[v] = 0;
        c[neighbor[v]] = 1;
      } else if (tmpc == 0) {
        c[v] = 1;
      } else {
        c[v] = 0;
      }
      t[v][neighbor[v]].first = t[neighbor[v]][v].first = d[v];
    }
    for (int i = 0; i < n; ++i) {
      if (c[i] < 0) {
        for (auto v : t[i]) {
          if (d[v.first] < d[i]) {
            c[i] = c[v.first];
            t[i][v.first].first = t[v.first][i].first = d[i] - d[v.first];
            break;
          }
        }
      }
    }
    vector<int> ans(m);
    for (int i = 0; i < n; ++i) {
      for (auto v : t[i]) {
        ans[v.second.second] = v.second.first;
      }
    }
    for (int i = 0; i < n; ++i) {
      cout << ("BW"[c[i]]);
    }
    cout << endl;
    for (int i = 0; i < m; ++i) {
      cout << ans[i] << endl;
    }
  }
};
}  // namespace Problem
int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  long long n = 0, m;
  std::cin >> n >> m;
  Problem::Solver2 sol(n, m);
  sol.solve();
  return 0;
}
