#include <bits/stdc++.h>
int n, m;
char str[5];
int edge[110][110];
int win[110][110][30];
char out[110];
int dfs(int u, int v, int c) {
  if (win[u][v][c] != -1) return win[u][v][c];
  int &ret = win[u][v][c];
  ret = 0;
  for (int i = 1; i <= n; ++i) {
    if (edge[u][i] >= c && dfs(v, i, edge[u][i]) == 0) {
      ret = 1;
    }
  }
  return ret;
}
int main() {
  scanf("%d%d", &n, &m);
  memset(edge, -1, sizeof edge);
  memset(win, -1, sizeof win);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d%s", &u, &v, str);
    edge[u][v] = str[0] - 'a';
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      out[j - 1] = (dfs(i, j, 0) == 1 ? 'A' : 'B');
    }
    out[n] = 0;
    puts(out);
  }
  return 0;
}
