#include <bits/stdc++.h>
using namespace std;
int n, m;
int s[111][111];
bool f[111][111][26];
int que[111], head, tail, indo[111];
void topo() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (s[i][j] != -1) indo[j]++;
  head = tail = 1;
  for (int i = 1; i <= n; i++)
    if (indo[i] == 0) que[tail++] = i;
  while (head != tail) {
    int now = que[head++];
    for (int i = 1; i <= n; i++)
      if (s[now][i] != -1) {
        indo[i]--;
        if (indo[i] == 0) que[tail++] = i;
      }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  char c;
  memset(s, -1, sizeof(s));
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d%d", &x, &y);
    while ((c = getchar()) < 'a' || c > 'z')
      ;
    s[x][y] = c - 'a';
  }
  topo();
  for (int i = n; i; i--) {
    for (int j = n; j >= i; j--)
      for (int k = 0; k < 26; k++) {
        f[que[i]][que[j]][k] = 0;
        for (int r = 1; r <= n; r++)
          if (s[que[i]][r] >= k)
            f[que[i]][que[j]][k] |= (f[que[j]][r][s[que[i]][r]] == 0);
      }
    for (int j = n; j >= i; j--)
      for (int k = 0; k < 26; k++) {
        f[que[j]][que[i]][k] = 0;
        for (int r = 1; r <= n; r++)
          if (s[que[j]][r] >= k)
            f[que[j]][que[i]][k] |= (f[que[i]][r][s[que[j]][r]] == 0);
      }
  }
  for (int i = 1; i <= n; i++, puts(""))
    for (int j = 1; j <= n; j++) putchar(f[i][j][0] ? 'A' : 'B');
  return 0;
}
