#include <bits/stdc++.h>
using namespace std;
int win[101][101][26];
vector<pair<int, int> > adj[101];
int whoWin(int a, int b, int minC) {
  int &ret = win[a][b][minC];
  if (ret != 0) return ret;
  for (int i = 0; i < adj[a].size(); ++i) {
    int next = adj[a][i].first;
    int cost = adj[a][i].second;
    if (cost < minC) continue;
    if (whoWin(b, next, cost) == -1) return ret = 1;
  }
  return ret = -1;
}
int main() {
  int n, m, v, u;
  char c;
  scanf("%d %d", &n, &m);
  while (m--) {
    scanf("%d %d %c", &v, &u, &c);
    adj[v].push_back({u, c - 'a'});
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) printf("%c", whoWin(i, j, 0) == 1 ? 'A' : 'B');
    printf("\n");
  }
}
