#include <bits/stdc++.h>
using namespace std;
const int N = 256, M = 1e5 + 5;
int one[N], idx;
int ver[M], Next[M], edge[M];
inline void AddEdge(int a, int b, int c) {
  Next[idx] = one[a];
  ver[idx] = b;
  edge[idx] = c;
  one[a] = idx++;
}
int n, m;
int f[N][N][27];
int SG(int u, int v, int c) {
  if (~f[u][v][c]) return f[u][v][c];
  set<int> S;
  for (int i = one[u], y; ~i; i = Next[i]) {
    y = ver[i];
    if (edge[i] >= c) S.insert(SG(v, y, edge[i]));
  }
  for (int i = 0;; i++)
    if (!S.count(i)) return f[u][v][c] = i;
}
int main() {
  int i, j;
  int x, y;
  char c;
  cin >> n >> m;
  memset(one, -1, sizeof one);
  for (i = 1; i <= m; i++) {
    cin >> x >> y >> c;
    AddEdge(x, y, c - 'a');
  }
  memset(f, -1, sizeof f);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      if (SG(i, j, 0))
        putchar('A');
      else
        putchar('B');
    }
    puts("");
  }
  return 0;
}
