#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 1e2 + 5;
const int inf = 0x3f3f3f3f;
struct node {
  int v, next, w;
} e[maxn * maxn / 2];
int head[maxn], tot, dp[maxn][maxn][30];
int dfs(int u, int v, int val) {
  if (dp[u][v][val] != -1) return dp[u][v][val];
  dp[u][v][val] = 0;
  for (int i = head[u]; i + 1; i = e[i].next) {
    if (e[i].w >= val && !dfs(v, e[i].v, e[i].w)) dp[u][v][val] = 1;
  }
  return dp[u][v][val];
}
void add(int u, int v, int w) {
  e[tot].v = v;
  e[tot].w = w;
  e[tot].next = head[u];
  head[u] = tot++;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  memset(head, -1, sizeof(head));
  memset(dp, -1, sizeof(dp));
  while (m--) {
    int u, v;
    char s[2];
    scanf("%d%d%s", &u, &v, s);
    add(u, v, s[0] - 'a');
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dfs(i, j, 0))
        printf("A");
      else
        printf("B");
    }
    puts("");
  }
}
