#include <bits/stdc++.h>
using namespace std;
int mp[200][200];
int dp[26][200][200];
int n, m;
int DP(char t, int i, int j) {
  if (dp[t][i][j] >= 0) return dp[t][i][j];
  for (int k = 1; k <= n; k++)
    if (t <= mp[i][k] && DP(mp[i][k], j, k) == 0) return dp[t][i][j] = 1;
  return dp[t][i][j] = 0;
}
int main() {
  scanf("%d%d", &n, &m);
  memset(dp, -1, sizeof(dp));
  memset(mp, -1, sizeof(mp));
  for (int i = 1, u, v; i <= m; i++) {
    char ch[3];
    scanf("%d%d%s", &u, &v, ch);
    mp[u][v] = ch[0] - 'a';
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) DP(0, i, j);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (dp[0][i][j] == 1)
        printf("A");
      else
        printf("B");
    printf("\n");
  }
  return 0;
}
