#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int mp[N][N];
int dp[N][N][30];
int n, m;
int dfs(int u, int v, int last) {
  if (dp[u][v][last] != -1) return dp[u][v][last];
  for (int i = 1; i <= n; ++i) {
    if (mp[u][i] - 'a' >= last && dfs(v, i, mp[u][i] - 'a') == 0)
      return dp[u][v][mp[u][i] - 'a'] = 1;
  }
  return dp[u][v][last] = 0;
}
int main() {
  int a, b;
  char c[5];
  memset(dp, -1, sizeof(dp));
  memset(mp, 0, sizeof(mp));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%s", &a, &b, c);
    mp[a][b] = c[0];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (dfs(i, j, 0))
        putchar('A');
      else
        putchar('B');
    }
    puts("");
  }
  return 0;
}
