#include <bits/stdc++.h>
using namespace std;
int n, m;
int adj[110][110] = {0};
int dp[110][110][50] = {0};
int func(int v, int u, int c) {
  if (dp[v][u][c] != -1) return dp[v][u][c];
  for (int i = 1; i <= n; i++) {
    if (adj[v][i] != -1 && adj[v][i] >= c) {
      if (func(u, i, adj[v][i]) == 2) {
        dp[v][u][c] = 1;
        return 1;
      }
    }
  }
  dp[v][u][c] = 2;
  return 2;
}
int main() {
  for (int i = 0; i < 110; i++)
    for (int j = 0; j < 110; j++) adj[i][j] = -1;
  for (int i = 0; i < 110; i++)
    for (int j = 0; j < 110; j++)
      for (int k = 0; k < 50; k++) dp[i][j][k] = -1;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v, c;
    char ch;
    cin >> u >> v >> ch;
    c = ch - 'a';
    adj[u][v] = c;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cout << (func(i, j, 0) == 1 ? 'A' : 'B');
    }
    cout << endl;
  }
  return 0;
}
