#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int u, v, d;
};
vector<Edge> edges;
vector<int> G[110];
int f[110][110][27];
int dfs(int i, int j, int last) {
  if (f[i][j][last] != -1) return f[i][j][last];
  if (i == j) return f[i][j][last] = 1;
  int leni = G[i].size();
  for (int p1 = 0; p1 < leni; p1++) {
    Edge x = edges[G[i][p1]];
    if (x.d < last) continue;
    if (dfs(j, x.v, x.d) == 1) return f[i][j][last] = 0;
  }
  return f[i][j][last] = 1;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    char c;
    scanf("%d%d %c", &x, &y, &c);
    edges.push_back((Edge){x, y, c - 'a'});
    G[x].push_back(edges.size() - 1);
  }
  memset(f, -1, sizeof(f));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      f[i][j][0] = dfs(i, j, 0);
      printf("%c", f[i][j][0] == 0 ? 'A' : 'B');
    }
    printf("\n");
  }
  return 0;
}
