#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
void init() {
  iostream::sync_with_stdio(false);
  cout << fixed << setprecision(100);
}
long long ans[300000];
long long coloring[300000];
long long now_dist[300000];
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> inputs;
  for (long long(i) = 0; (i) < (n); ++(i)) {
    long long a;
    cin >> a;
    inputs.push_back(a);
    coloring[i] = 2;
  }
  vector<tuple<long long, long long, long long, long long>> edges;
  for (long long(i) = 0; (i) < (m); ++(i)) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    if (inputs[a] == inputs[b]) {
      if (coloring[a] == 2 && coloring[b] == 2) {
        coloring[a] = 0;
        coloring[b] = 1;
        ans[i] = inputs[a];
        now_dist[a] = ans[i];
        now_dist[b] = ans[i];
        continue;
      }
      if (coloring[a] == 2 || coloring[b] == 2) {
        if (coloring[a] == 2) {
          coloring[a] = (coloring[b] + 1) % 2;
        } else {
          coloring[a] = (coloring[b] + 1) % 2;
        }
        ans[i] = inputs[a];
        now_dist[a] = ans[i];
        now_dist[b] = ans[i];
        continue;
      }
      ans[i] = 1e9;
      continue;
    }
    if (inputs[a] > inputs[b]) swap(a, b);
    edges.push_back(make_tuple(inputs[a], a, b, i));
  }
  sort((edges).begin(), (edges).end());
  for (auto x : edges) {
    if (coloring[get<1>(x)] == 2) {
      cout << -1 << endl;
      return;
    }
    if (coloring[get<2>(x)] == 2) {
      coloring[get<2>(x)] = coloring[get<1>(x)];
      long long geko = inputs[get<2>(x)] - now_dist[get<1>(x)];
      ans[get<3>(x)] = geko;
      now_dist[get<2>(x)] = inputs[get<2>(x)];
    } else {
      ans[get<3>(x)] = 1e9;
    }
  }
  for (long long(i) = 0; (i) < (n); ++(i)) {
    if (coloring[i] == 2) {
      cout << "-1" << endl;
      return;
    }
  }
  for (long long(i) = 0; (i) < (n); ++(i)) {
    if (coloring[i] == 0) {
      cout << "B";
    } else {
      cout << "W";
    }
  }
  cout << endl;
  for (long long(i) = 0; (i) < (m); ++(i)) {
    cout << ans[i] << endl;
  }
}
int main() {
  init();
  solve();
}
