#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int maxn = 105;
const int maxm = 1e5 + 5;
struct edge {
  int v, w;
  int next;
} e[maxm];
int total = 0;
int head[maxn];
void addedge(int u, int v, int w) {
  total++;
  e[total].v = v;
  e[total].w = w;
  e[total].next = head[u];
  head[u] = total;
}
int dp[maxn][maxn][30];
int dfs(int i, int j, int prew) {
  if (dp[i][j][prew]) return dp[i][j][prew];
  for (int k = head[i]; k; k = e[k].next) {
    int v = e[k].v;
    int w = e[k].w;
    if (w >= prew) {
      if (dfs(j, v, w) == 2) {
        return dp[i][j][w] = 1;
      }
    }
  }
  return dp[i][j][prew] = 2;
}
int main() {
  memset(dp, 0, sizeof(dp));
  int n, m;
  scanf("%d%d", &n, &m);
  while (m--) {
    int u, v;
    char value;
    scanf("%d %d %c", &u, &v, &value);
    addedge(u, v, value - '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");
  }
}
