#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int MAXN = 300005;
struct list {
  int l, lt[MAXN], nt[MAXN], x[MAXN], y[MAXN];
  void clear() {
    l = 0;
    memset(lt, 0, sizeof(lt));
  }
  void addedge(int a, int b, int c) {
    nt[++l] = lt[a];
    lt[a] = l;
    x[l] = b;
    y[l] = c;
  }
} E;
char s[MAXN], ch;
int n, m, q, a[MAXN], f[105][105][30];
int work(int x, int y, int z) {
  if (f[x][y][z] != -1) return f[x][y][z];
  for (int i = E.lt[x], j, k; i; i = E.nt[i]) {
    j = E.x[i];
    k = E.y[i];
    if (k >= z && !work(y, j, k)) return f[x][y][z] = 1;
  }
  return f[x][y][z] = 0;
}
int main() {
  n = read();
  m = read();
  E.clear();
  for (int i = (1); i <= (m); ++i) {
    int x, y, z;
    x = read();
    y = read();
    z = getchar() - 'a' + 1;
    E.addedge(x, y, z);
  }
  memset(f, -1, sizeof(f));
  for (int i = (1); i <= (n); ++i) {
    for (int j = (1); j <= (n); ++j) printf("%c", work(i, j, 0) ? 'A' : 'B');
    printf("\n");
  }
  return 0;
}
