#include <bits/stdc++.h>
using namespace std;
int n, m;
int tot, h[105];
int f[105][105][30];
struct node {
  int to, nxt, v;
} e[5005];
void add_edge(int x, int y, int v) {
  e[++tot].to = y;
  e[tot].v = v;
  e[tot].nxt = h[x];
  h[x] = tot;
}
int dfs(int x, int y, int c) {
  if (f[x][y][c] != 0) return f[x][y][c];
  int ans = -1;
  for (int i = h[x]; i; i = e[i].nxt) {
    if (e[i].v >= c && dfs(y, e[i].to, e[i].v) == -1) {
      ans = 1;
      break;
    }
  }
  f[x][y][c] = ans;
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  int u, v;
  char s[5];
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%s", &u, &v, &s);
    add_edge(u, v, s[0] - 'a');
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dfs(i, j, 0) == 1)
        printf("A");
      else
        printf("B");
    }
    printf("\n");
  }
  return 0;
}
