#include <bits/stdc++.h>
int n, m;
int adj[100 + 1][100 + 1];
int dp[100 + 1][100 + 1][26 + 1];
int dfs(int i, int j, int c) {
  if (dp[i][j][c] != -1) return dp[i][j][c];
  for (int k = 1; k <= n; k++) {
    if (adj[i][k] >= c && !dfs(j, k, adj[i][k])) return dp[i][j][c] = 1;
  }
  return dp[i][j][c] = 0;
}
int main(void) {
  scanf("%d%d", &n, &m);
  memset(adj, -1, sizeof(adj));
  memset(dp, -1, sizeof(dp));
  while (m--) {
    int u, v;
    char ch;
    scanf("%d%d %c", &u, &v, &ch);
    adj[u][v] = ch - 'a';
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dfs(i, j, 0))
        putchar('A');
      else
        putchar('B');
    }
    putchar('\n');
  }
  return 0;
}
