#include <bits/stdc++.h>
using namespace std;
int dp[105][105][30][2];
int n, m;
vector<int> g[105];
int val[105][105];
int dfs(int x, int y, int las, int turn) {
  if (dp[x][y][las][turn] != -1) return dp[x][y][las][turn];
  int f = 0;
  if (turn == 0) {
    int len = g[x].size();
    for (int i = 0; i < len; i++) {
      int to = g[x][i];
      if (val[x][to] >= las && !dfs(to, y, val[x][to], 1)) f = 1;
    }
  } else {
    int len = g[y].size();
    for (int i = 0; i < len; i++) {
      int to = g[y][i];
      if (val[y][to] >= las && !dfs(x, to, val[y][to], 0)) f = 1;
    }
  }
  return dp[x][y][las][turn] = f;
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    char dd;
    cin >> a >> b >> dd;
    g[a].push_back(b);
    val[a][b] = dd - 'b' + 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (dfs(i, j, 0, 0) == 1)
        printf("A");
      else
        printf("B");
    printf("\n");
  }
  return 0;
}
