#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, dp[108][108][28], dis[108][108];
int DP(int s, int t, int w) {
  if (dp[s][t][w - 'a'] >= 0) return dp[s][t][w - 'a'];
  for (int i = 1; i <= n; ++i)
    if (dis[s][i] >= w && (DP(t, i, dis[s][i]) == 0))
      return dp[s][t][w - 'a'] = 1;
  return dp[s][t][w - 'a'] = 0;
}
int main() {
  char z;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d %c", &x, &y, &z);
    dis[x][y] = z;
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) DP(i, j, 'a');
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) printf("%c", dp[i][j][0] ? 'A' : 'B');
    puts("");
  }
}
