#include <bits/stdc++.h>
using namespace std;
int dp[101][101][2][27];
vector<pair<int, int> > G[101];
int sol(int Ap, int Bp, bool turn, int pre) {
  if (Ap == Bp) {
    if (turn)
      return 1;
    else
      return 2;
  }
  if (dp[Ap][Bp][turn][pre] != 0) return dp[Ap][Bp][turn][pre];
  int ret = 0;
  if (turn == 0) {
    for (int i = 0; i < G[Ap].size(); ++i) {
      if (pre <= G[Ap][i].second) {
        if (sol(G[Ap][i].first, Bp, !turn, G[Ap][i].second) == 1) {
          ret = 1;
          break;
        } else
          ret = 2;
      }
    }
    if (ret == 1) {
      for (int i = 0; i <= pre; ++i) dp[Ap][Bp][turn][i] = 1;
      return 1;
    } else {
      dp[Ap][Bp][turn][pre] = 2;
      return 2;
    }
  } else {
    for (int i = 0; i < G[Bp].size(); ++i) {
      if (pre <= G[Bp][i].second) {
        if (sol(Ap, G[Bp][i].first, !turn, G[Bp][i].second) == 2) {
          ret = 2;
          break;
        } else
          ret = 1;
      }
    }
    if (ret == 2) {
      for (int i = 0; i <= pre; ++i) dp[Ap][Bp][turn][i] = 2;
      return 2;
    } else {
      dp[Ap][Bp][turn][pre] = 1;
      return 1;
    }
  }
}
int main() {
  int n, m, m1, m2;
  char c;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d %c", &m1, &m2, &c);
    G[m1].push_back({m2, c - 'a' + 1});
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (sol(i, j, 0, 0) == 1)
        printf("A");
      else
        printf("B");
    }
    printf("\n");
  }
  return 0;
}
