#include <bits/stdc++.h>
using namespace std;
vector<long long int> a;
vector<vector<long long int>> G =
    vector<vector<long long int>>(200001, vector<long long int>(0, 0));
vector<vector<long long int>> T =
    vector<vector<long long int>>(200001, vector<long long int>(0, 0));
vector<long long int> par(200001, -1);
map<pair<long long int, long long int>, long long int> edge;
void err() {
  std::cout << -1 << '\n';
  exit(0);
}
vector<long long int> color(200001, -1);
void dfs(long long int now, long long int omit, long long int d) {
  if (color[now] != -1) return;
  color[now] = d;
  for (auto to : T[now]) {
    if (to == omit) continue;
    long long int x = min(now, to);
    long long int y = max(now, to);
    edge.emplace(make_pair(x, y), a[now]);
    dfs(to, -1, d ^ 1);
  }
}
int main(int argc, char const *argv[]) {
  long long int n, m;
  std::cin >> n >> m;
  for (long long int i = 0; i < n; i++) {
    long long int b;
    scanf("%lld", &b);
    a.push_back(b);
  }
  vector<vector<long long int>> dat =
      vector<vector<long long int>>(m, vector<long long int>(2, 0));
  for (long long int i = 0; i < m; i++) {
    long long int x, y;
    scanf("%lld %lld", &x, &y);
    x--, y--;
    G[x].push_back(y);
    G[y].push_back(x);
    dat[i][0] = x, dat[i][1] = y;
  }
  for (int i = 0; i < n; i++) {
    long long int min_num = 10000000000, idx = -1;
    for (auto to : G[i]) {
      if (a[to] <= a[i] && a[to] < min_num) {
        if (a[to] < min_num || to < idx) min_num = a[to], idx = to;
      }
    }
    if (idx == -1) err();
    T[idx].push_back(i);
    par[i] = idx;
  }
  for (long long int i = 0; i < n; i++) {
    if (par[par[i]] == i) {
      long long int x = min(i, par[i]);
      long long int y = max(i, par[i]);
      edge.emplace(make_pair(x, y), a[i]);
      dfs(i, par[i], 0);
      dfs(par[i], i, 1);
    }
  }
  for (int i = 0; i < n; i++)
    std::cout << (color[i] ? 'W' : 'B') << (i == n - 1 ? "\n" : "");
  for (int i = 0; i < m; i++) {
    long long int x = min(dat[i][0], dat[i][1]);
    long long int y = max(dat[i][0], dat[i][1]);
    auto itr = edge.find(make_pair(x, y));
    if (itr == edge.end())
      std::cout << 1000000000 << '\n';
    else
      std::cout << (*itr).second << '\n';
  }
  return 0;
}
