#include <bits/stdc++.h>
const int maxn = 1e2 + 5;
int n, m, head[maxn], E[maxn * maxn], V[maxn * maxn], W[maxn * maxn], cnt;
int dp[maxn][maxn][27];
inline void read(int &now) {
  char Cget;
  now = 0;
  while (!isdigit(Cget = getchar()))
    ;
  while (isdigit(Cget)) {
    now = now * 10 + Cget - '0';
    Cget = getchar();
  }
}
inline void edge_add(int u, int v, int w) {
  E[++cnt] = head[u];
  V[cnt] = v;
  W[cnt] = w;
  head[u] = cnt;
}
int dfs(int x, int y, int c) {
  if (dp[x][y][c] >= 0) return dp[x][y][c];
  for (int i = head[x]; i != 0; i = E[i])
    if (W[i] >= c && !dfs(y, V[i], W[i])) return dp[x][y][c] = 1;
  return dp[x][y][c] = 0;
}
int main() {
  read(n);
  read(m);
  char op[3];
  memset(dp, -1, sizeof(dp));
  for (int i = 1, u, v; i <= m; i++) {
    read(u);
    read(v);
    scanf("%s", op);
    edge_add(u, v, op[0] - 'a' + 1);
  }
  for (int i = 1; i <= n; i++, printf("\n"))
    for (int v = 1; v <= n; v++)
      if (dfs(i, v, 0))
        putchar('A');
      else
        putchar('B');
  return 0;
}
