#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > g[110];
int dp[110][110][26][2];
int solve(int i, int j, int last, int turn) {
  int &ans = dp[i][j][last][turn];
  if (ans != -1) return ans;
  if (!turn) {
    ans = 0;
    for (auto e : g[i]) {
      if (e.second >= last) ans |= solve(e.first, j, e.second, turn ^ 1);
      if (ans) break;
    }
    return ans;
  } else {
    ans = 1;
    for (auto e : g[j]) {
      if (e.second >= last) ans &= solve(i, e.first, e.second, turn ^ 1);
      if (!ans) break;
    }
    return ans;
  }
  return ans;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int u, v;
  char w;
  while (m--) {
    scanf("%d %d %c", &u, &v, &w);
    u--, v--;
    g[u].push_back({v, w - '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;
}
