#include <bits/stdc++.h>
using namespace std;
long long dp[102][102][30][2];
struct node {
  int v, val;
};
int n, m;
vector<node> g[200];
int dfs(int x, int y, int z, int t) {
  if (dp[x][y][z][t] != -1) return dp[x][y][z][t];
  int flag = 0;
  if (t == 1) {
    int l = g[x].size();
    for (int i = 0; i < l; i++) {
      node temp = g[x][i];
      if (temp.val >= z && !dfs(temp.v, y, temp.val, 2)) flag = 1;
    }
  } else {
    int l = g[y].size();
    for (int i = 0; i < l; i++) {
      node temp = g[y][i];
      if (temp.val >= z && !dfs(x, temp.v, temp.val, 1)) flag = 1;
    }
  }
  return dp[x][y][z][t] = flag;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v, val;
    scanf("%d %d %c", &u, &v, &val);
    getchar();
    g[u].push_back((node){v, val - 'a'});
  }
  memset(dp, -1, sizeof(dp));
  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;
}
