#include <bits/stdc++.h>
const int N = 100010;
using namespace std;
int ver[10010], Next[10010], head[110], edge[10010];
int tot;
void add(int x, int y, int z) {
  ver[++tot] = y;
  edge[tot] = z;
  Next[tot] = head[x];
  head[x] = tot;
}
int dp[110][110][30];
int dfs(int ii, int jj, int kk) {
  if (dp[ii][jj][kk]) return dp[ii][jj][kk];
  int x = ii;
  for (int i = head[x]; i; i = Next[i]) {
    int y = ver[i], z = edge[i];
    if (z < kk) continue;
    if (dfs(jj, y, z) == 2) return dp[ii][jj][kk] = 1;
  }
  return dp[ii][jj][kk] = 2;
}
int main() {
  for (int i = 0; i < 110; i++)
    for (int j = 0; j < 110; j++)
      for (int k = 0; k < 30; k++) dp[i][j][k] = 0;
  int n, m;
  scanf("%d%d", &n, &m);
  tot = 0;
  int x, y;
  char z;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %c", &x, &y, &z);
    int zz = z - 'a' + 1;
    add(x, y, zz);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dfs(i, j, 0) == 1)
        printf("A");
      else
        printf("B");
    }
    printf("\n");
  }
  return 0;
}
