#include <bits/stdc++.h>
using namespace std;
int n, m;
bool dp[110][110][100][2];
bool vis[110][110][100][2];
int read() {
  int ret = 0, neg = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ret = ret * 10 + c - '0';
    c = getchar();
  }
  return ret * neg;
}
struct Edge {
  int to, val, next;
};
Edge edge[110 * 110];
int toedge[110];
int cnt;
void add(int from, int to, int val) {
  edge[++cnt] = {to, val, toedge[from]};
  toedge[from] = cnt;
}
bool dfs(int x, int y, int maxc, int rnd) {
  if (vis[x][y][maxc][rnd % 2]) return dp[x][y][maxc][rnd % 2];
  vis[x][y][maxc][rnd % 2] = 1;
  if (rnd % 2 == 1) {
    for (int i = toedge[x]; i; i = edge[i].next) {
      int to = edge[i].to;
      if (edge[i].val >= maxc)
        if (!dfs(to, y, edge[i].val, rnd + 1)) {
          dp[x][y][maxc][rnd % 2] = true;
          return true;
        }
    }
    dp[x][y][maxc][rnd % 2] = false;
    return false;
  } else {
    for (int i = toedge[y]; i; i = edge[i].next) {
      int to = edge[i].to;
      if (edge[i].val >= maxc)
        if (!dfs(x, to, edge[i].val, rnd + 1)) {
          dp[x][y][maxc][rnd % 2] = true;
          return true;
        }
    }
    dp[x][y][maxc][rnd % 2] = false;
    return false;
  }
}
int main() {
  n = read();
  m = read();
  int a, b;
  char c;
  for (int i = 1; i <= m; i++) {
    a = read();
    b = read();
    cin >> c;
    add(a, b, c - 'a' + 1);
  }
  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");
    puts("");
  }
}
