#include <bits/stdc++.h>
using namespace std;
const int N = 105, A = 26;
bool win[N][N][A], known[N][N][A];
char g[N][N];
int n;
bool follow(int u, int v, char c) {
  if (known[u][v][c - 'a']) return win[u][v][c - 'a'];
  for (int i = 1; i <= n; ++i)
    if (g[u][i] >= c) win[u][v][c - 'a'] |= !follow(v, i, g[u][i]);
  known[u][v][c - 'a'] = 1;
  return win[u][v][c - 'a'];
}
int main() {
  int m;
  scanf("%d%d", &n, &m);
  while (m--) {
    int a, b;
    char c;
    scanf("%d%d %c", &a, &b, &c);
    g[a][b] = c;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      printf("%c", follow(i, j, 'a') ? 'A' : 'B');
    }
    printf("\n");
  }
}
