#include <bits/stdc++.h>
using namespace std;
const int N = 112;
int n, m;
char dp[N][N][26][2];
vector<pair<int, int> > g[N];
char solve(const int i, const int j, const int before, const bool current) {
  if (dp[i][j][before][current] != -1) return dp[i][j][before][current];
  int ans = 0;
  int x = current ? j : i;
  for (auto k : g[x])
    if (k.second >= before) {
      if (current)
        ans = max(ans, solve(i, k.first, k.second, current ^ 1) ^ 1);
      else
        ans = max(ans, solve(k.first, j, k.second, current ^ 1) ^ 1);
    }
  return dp[i][j][before][current] = ans;
}
int main() {
  scanf("%d %d", &n, &m);
  while (m-- > 0) {
    char c;
    int x, y;
    scanf("%d %d %c", &x, &y, &c), --x, --y;
    g[x].push_back(make_pair(y, c - 'a'));
  }
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) printf("%c", solve(i, j, 0, 0) ? 'A' : 'B');
    puts("");
  }
  return 0;
}
