#include <bits/stdc++.h>
using namespace std;
const int maxi = 1e6 + 10;
int a[maxi];
vector<pair<int, int>> v[maxi];
int d[maxi];
int n, m;
string s;
pair<int, int> b[maxi];
int rez[maxi];
int ob[maxi];
int sz = 0;
void dfs(int x, int col) {
  ob[x] = 1;
  if (col) s[x - 1] = 'B';
  for (auto i : v[x])
    if (!ob[i.first] && d[x] <= d[i.first]) {
      rez[i.second] = d[i.first];
      dfs(i.first, col ^ 1);
    }
}
int check() {
  for (int i = 0; i < n; i++) s += 'W';
  dfs(b[1].second, 1);
  return 1;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    b[i] = {d[i], i};
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back({y, i});
    v[y].push_back({x, i});
  }
  sort(b + 1, b + n + 1);
  if (b[1].first != b[2].first) return !printf("-1\n");
  if (check()) {
    for (int i = 1; i <= m; i++)
      if (!rez[i]) rez[i] = 1e9;
    cout << s << endl;
    for (int i = 1; i <= m; i++) printf("%d\n", rez[i]);
    printf("\n");
    return 0;
  } else
    printf("-1\n");
  return 0;
}
