#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long int INF = (long long int)1e9;
struct Vertex {
  vector<pair<long long int, long long int> > node;
};
Vertex V[100005];
pair<long long int, long long int> D[100005];
long long int C[200005];
long long int S[100005];
int main() {
  long long int N, M;
  cin >> N >> M;
  for (long long int(i) = (0); (i) < (N); ++(i)) {
    cin >> D[i].first;
    D[i].second = i;
  }
  sort(D, D + N,
       [](pair<long long int, long long int> a,
          pair<long long int, long long int> b) { return a.first < b.first; });
  for (long long int(i) = (0); (i) < (M); ++(i)) {
    long long int a, b;
    cin >> a >> b;
    a--;
    b--;
    V[a].node.push_back(pair<long long int, long long int>(b, i));
    V[b].node.push_back(pair<long long int, long long int>(a, i));
  }
  if (D[0].first != D[1].first) {
    cout << -1 << endl;
    return 0;
  }
  for (long long int(i) = (0); (i) < (N); ++(i)) {
    cout << 'B';
  }
  cout << endl;
  for (long long int(i) = (0); (i) < (M); ++(i)) {
    cout << 0 << endl;
  }
  return 0;
}
