#include
#include
#include
#include
using namespace std;
const int maxn=200005;
typedef long long ll;
vector> graph[10005];
int dp[101][101][28][2];
int rec(int max_pos, int lucas_pos, int last_char, int turn) {
if(dp[max_pos][lucas_pos][last_char][turn] != -1) {
return dp[max_pos][lucas_pos][last_char][turn];
}
int res;
if(turn == 0) {
res = -(2e9);
for(int i = 0; i < graph[max_pos].size(); i++) {
int neighbour = graph[max_pos][i].first;
int next_char = graph[max_pos][i].second;
if(last_char <= next_char) {
res = max(res, rec(neighbour, lucas_pos, next_char, 1));
}
}
}
else {
res = (2e9);
for(int i = 0; i < graph[lucas_pos].size(); i++) {
int neighbour = graph[lucas_pos][i].first;
int next_char = graph[lucas_pos][i].second;
if(last_char <= next_char) {
res = min(res, rec(max_pos, neighbour, next_char, 0));
}
}
}
return dp[max_pos][lucas_pos][last_char][turn] = res;
}
int main()
{
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i++) {
int a, b;
char c;
cin >> a >> b >> c;
a--; b--;
graph[a].push_back(make_pair(b, (c - 'a') + 1));
}
memset(dp, -1, sizeof dp);
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(rec(i, j, 0, 0) == 2e9) {
cout << "A";
}
else {
cout << "B";
}
}
cout << endl;
}
return 0;
}