#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int N = 110;
const int M = N * N;
struct edge {
  int to, nxt;
  int c;
  edge() {}
  edge(int _to, int _nxt, int _c) : to(_to), nxt(_nxt), c(_c) {}
} E[M];
int head[N], tot;
int dp[130][N][N];
void init() {
  memset(head, -1, sizeof(head));
  tot = 0;
}
inline void add(int s, int t, int c) {
  E[tot] = edge(t, head[s], c);
  head[s] = tot++;
}
int dfs(int level, int fi, int se) {
  if (~dp[level][fi][se]) return dp[level][fi][se];
  for (int i = head[fi]; ~i; i = E[i].nxt) {
    int v = E[i].to;
    if (E[i].c >= level) {
      if (!dfs(E[i].c, se, v)) return dp[level][fi][se] = 1;
    }
  }
  return dp[level][fi][se] = 0;
}
int main(void) {
  register int n, m, a, b, i, j;
  char c[5];
  while (~scanf("%d%d", &n, &m)) {
    init();
    memset(dp, -1, sizeof(dp));
    for (i = 1; i <= m; ++i) {
      scanf("%d%d%s", &a, &b, c);
      add(a, b, (int)c[0]);
    }
    for (i = 1; i <= n; ++i) {
      for (j = 1; j <= n; ++j) {
        if (dfs(0, i, j))
          putchar('A');
        else
          putchar('B');
      }
      puts("");
    }
  }
  return 0;
}
