#include <bits/stdc++.h>
using namespace std;
const int N = 105, M = 28;
vector<pair<int, int> > adj[N];
int dp[N][N][2][M];
int solve(int a, int b, int turn, int al) {
  int &ret = dp[a][b][turn][al];
  if (ret != -1) return ret;
  ret = 0;
  int u = a;
  if (turn) u = b;
  int v, alp, i;
  int na, nb;
  for (i = 0; i < adj[u].size(); ++i) {
    v = adj[u][i].first;
    alp = adj[u][i].second;
    if (al <= alp) {
      na = a;
      nb = b;
      if (turn)
        nb = v;
      else
        na = v;
      if (solve(na, nb, turn ^ 1, alp) == 0) return ret = 1;
    }
  }
  return ret;
}
int main() {
  memset(dp, -1, sizeof(dp));
  int n, m, i, j, a, b, v;
  char c;
  cin >> n >> m;
  for (i = 0; i < m; ++i) {
    scanf("%d%d", &a, &b);
    cin >> c;
    v = c - 'a' + 1;
    adj[a].push_back(make_pair(b, v));
  }
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= n; ++j) {
      if (solve(i, j, 0, 0))
        cout << "A";
      else
        cout << "B";
    }
    cout << endl;
  }
}
