#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define pii pair<int, int>
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef CB
freopen("be2.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
int N, M, A, B;
cin >> N >> M >> A >> B;
vector<vector<int>> g(N + 1);
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int> a(N + 1, -1);
vector<int> b(N + 1, -1);
deque<int> q;
a[A] = 0;
q.push_back(A);
while (!q.empty()) {
int i = q.front();
q.pop_front();
for (int j : g[i]) {
if (a[j] == -1) {
a[j] = a[i] + 1;
q.push_back(j);
}
}
}
b[B] = 0;
q.push_back(B);
while (!q.empty()) {
int i = q.front();
q.pop_front();
for (int j : g[i]) {
if (b[j] == -1) {
b[j] = b[i] + 1;
q.push_back(j);
}
}
}
int ans = 0;
multimap<int, int> ma, mb;
for (int i = 1; i <= N; i++) {
if (a[i] >= b[i]) {
ans += b[i];
ma.insert({a[i] - b[i], i});
}
else {
ans += a[i];
mb.insert({b[i] - a[i], i});
}
}
while (ma.size() > mb.size()) {
auto p = *ma.begin();
ma.erase(ma.begin());
mb.insert(p);
ans += p.first;
a[p.second]++;
swap(a[p.second], b[p.second]);
}
while (mb.size() > ma.size()) {
auto p = *mb.begin();
mb.erase(mb.begin());
ma.insert(p);
ans += p.first;
b[p.second]++;
swap(a[p.second], b[p.second]);
}
cout << ans << '\n';
for (int i = 1; i <= N; i++) {
if (a[i] >= b[i]) {
cout << 'B';
}
else {
cout << 'A';
}
}
cout << '\n';
return 0;
}