#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int G[N][N], dp[N][N][30];
int n, m;
int dfs(int x, int y, int k) {
  if (dp[x][y][k]) return dp[x][y][k];
  for (int i = 1; i <= n; i++) {
    if (G[x][i] >= k && dfs(y, i, G[x][i]) == 2) return dp[x][y][k] = 1;
  }
  return dp[x][y][k] = 2;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    char c;
    scanf("%d %d %c", &u, &v, &c);
    G[u][v] = c - 'a' + 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dfs(i, j, 1) == 1)
        printf("A");
      else
        printf("B");
    }
    puts("");
  }
  return 0;
}
