#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void ckmin(T &a, U b) {
  if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
  if (a < b) a = b;
}
const int INF = 1000000000;
const int MAXN = 100013;
int N, M;
int arr[MAXN];
vector<int> edge[MAXN];
bitset<MAXN> vis;
int ans[2 * MAXN];
map<int, int> eid[MAXN];
bitset<MAXN> color;
void dfs(int u) {
  vis[u] = true;
  for (int v : edge[u]) {
    if (vis[v]) continue;
    if (arr[v] < arr[u]) continue;
    if (arr[v] == arr[u]) {
      color[v] = !color[u];
      ans[eid[u][v]] = arr[v];
    } else {
      color[v] = color[u];
      ans[eid[u][v]] = arr[v] - arr[u];
    }
    dfs(v);
  }
}
int32_t main() {
  cout << fixed << setprecision(12);
  cerr << fixed << setprecision(4);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  for (auto i = (0); i < (N); i++) {
    cin >> arr[i];
  }
  for (auto i = (0); i < (M); i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    edge[u].push_back(v);
    edge[v].push_back(u);
    eid[u][v] = i;
    eid[v][u] = i;
    ans[i] = INF;
  }
  for (auto i = (0); i < (N); i++) {
    int mn = INF;
    for (int x : edge[i]) {
      ckmin(mn, arr[x]);
    }
    if (mn > arr[i]) {
      cout << "-1\n";
      return 0;
    }
  }
  for (auto i = (0); i < (N); i++) {
    if (!vis[i]) dfs(i);
  }
  for (auto i = (0); i < (N); i++) {
    cout << (color[i] ? 'B' : 'W');
  }
  cout << '\n';
  for (auto i = (0); i < (M); i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
