#include <bits/stdc++.h>
using namespace std;
vector<long long int> adj[(long long int)2e5];
long long int dis[(long long int)2e5];
unordered_map<long long int, long long int> ind;
bool vis[(long long int)2e5] = {0};
long long int has(long long int x, long long int y) {
  long long int a = min(x, y);
  long long int b = max(x, y);
  return a * 200000 + b;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  vector<pair<long long int, long long int>> info;
  for (long long int i = 0; i < (long long int)(n); i++) {
    cin >> dis[i];
    info.push_back(make_pair(dis[i], i));
  }
  sort(info.rbegin(), info.rend());
  long long int x, y;
  for (long long int i = 0; i < (long long int)(m); i++) {
    cin >> x >> y;
    x--, y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
    ind[has(x, y)] = i;
  }
  vector<long long int> cost(m);
  string ans = "";
  for (long long int i = 0; i < (long long int)(n); i++) ans += 'W';
  pair<long long int, long long int> temp = info.back();
  info.pop_back();
  vis[temp.second] = true;
  if (dis[info.back().second] != temp.first ||
      ind.find(has(temp.second, info.back().second)) == ind.end()) {
    cout << -1;
    return 0;
  }
  while (!info.empty()) {
    pair<long long int, long long int> temp = info.back();
    info.pop_back();
    bool done = false;
    long long int cur = temp.second;
    for (long long int child : adj[cur]) {
      if (vis[child] && !done) {
        if (dis[child] < dis[cur]) {
          ans[cur] = ans[child];
          cost[ind[has(cur, child)]] = dis[cur] - dis[child];
        } else {
          ans[cur] = (ans[child] == 'W' ? 'B' : 'W');
          cost[ind[has(cur, child)]] = dis[cur];
        }
        done = true;
      } else if (vis[child] && done) {
        cost[ind[has(cur, child)]] = 1e9;
      }
    }
    vis[cur] = true;
  }
  cout << ans;
  cout << '\n';
  for (long long int i = 0; i < (long long int)(m); i++) {
    cout << cost[i] << '\n';
  }
}
