#include <bits/stdc++.h>
using namespace std;
using llong = long long;
template <class T>
struct Edge {
  int src, to;
  T cost;
  Edge(){};
  Edge(int to, T cost) : src(-1), to(to), cost(cost){};
  Edge(int src, int to, T cost) : src(src), to(to), cost(cost){};
  operator int() const { return to; };
};
template <class T>
using WeightedGraph = vector<vector<Edge<T>>>;
using UnWeightedGraph = vector<vector<int>>;
const llong inf = 1e9;
chrono::system_clock::time_point start, end;
llong n, m;
llong d[100005];
char c[100005];
Edge<llong> e[200005];
WeightedGraph<llong> g(100005);
map<llong, map<llong, llong>> cost;
char inv(char c) { return c == 'W' ? 'B' : 'W'; }
bool dfs(int u, int par) {
  bool rec = (cost[u][par] == d[u] && c[par] != c[u]);
  bool x = true;
  for (int i = 0; i < g[u].size(); i++) {
    int to = g[u][i];
    if (c[to] == 'W' || c[to] == 'B') {
      if (c[to] != c[u] && d[to] >= d[u] && cost[to][u] != d[to]) {
        cost[to][u] = d[to];
        cost[u][to] = d[to];
        if (d[u] == d[to]) rec = true;
      }
      continue;
    }
    if (d[to] < d[u]) {
      c[to] = c[u];
      x &= dfs(to, u);
    } else {
      if (d[to] == d[u]) rec = true;
      cost[to][u] = d[to];
      cost[u][to] = d[to];
      c[to] = inv(c[u]);
      x &= dfs(to, u);
    }
  }
  for (int i = 0; i < g[u].size(); i++) {
    int to = g[u][i];
    if (c[to] != c[u] && cost[to][u] == d[u]) rec = true;
  }
  return rec & x;
}
int main() {
  mt19937 rnd((random_device())());
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
  }
  for (int i = 0; i < m; i++) {
    llong s, t;
    cin >> s >> t;
    e[i] = Edge<llong>(s, t, inf);
    g[s].emplace_back(t, inf);
    g[t].emplace_back(s, inf);
    cost[s][t] = inf;
    cost[t][s] = inf;
  }
  for (int _ = 0; _ < 100; _++) {
    for (int i = 0; i < m; i++) {
      cost[e[i].src][e[i].to] = inf;
      cost[e[i].to][e[i].src] = inf;
    }
    for (int i = 1; i <= n; i++) {
      c[i] = '\0';
      for (int j = 0; j < g[i].size(); j++) {
        g[i][j].cost = inf;
      }
    }
    int idx = rnd() % n + 1;
    c[idx] = 'B';
    if (dfs(idx, -1)) {
      puts(c + 1);
      for (int i = 0; i < m; i++) {
        cout << cost[e[i].src][e[i].to] << endl;
      }
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
