#include <bits/stdc++.h>
using namespace std;
const int lim = (int)1e9;
int D[100005], visit[100005], F[100005];
string S;
queue<pair<int, char> > Q;
vector<pair<int, int> > V;
vector<pair<int, int> > X[100005];
void bfs(int s1, int s2) {
  Q.push({s1, 'W'});
  Q.push({s2, 'B'});
  visit[s1] = visit[s2] = 1;
  while (!Q.empty()) {
    int q = Q.front().first;
    char col = Q.front().second == 'W' ? 'B' : 'W';
    S[q - 1] = Q.front().second;
    Q.pop();
    for (auto x : X[q]) {
      int node = x.first;
      int indx = x.second;
      if (visit[node]) continue;
      visit[node] = 1;
      Q.push({node, col});
      F[indx] = D[node];
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
  int N, M;
  cin >> N >> M;
  S.resize(N);
  for (int i = 1; i <= N; i++) {
    int d;
    cin >> d;
    D[i] = d;
    V.push_back({d, i});
  }
  for (int i = 1; i <= M; i++) {
    int x, y;
    cin >> x >> y;
    X[x].push_back({y, i});
    X[y].push_back({x, i});
    F[i] = lim;
  }
  sort(V.begin(), V.end());
  if (V[0].first != V[1].first) {
    cout << -1 << "\n";
    return 0;
  }
  for (auto v : X[V[0].second])
    if (v.first == V[1].second) F[v.second] = V[0].first;
  bfs(V[0].second, V[1].second);
  cout << S << "\n";
  for (int i = 1; i <= M; i++) cout << F[i] << "\n";
  return 0;
}
