#include <bits/stdc++.h>
using namespace std;
int graph[101][101];
int dp[101][101][26];
int dfs(int x, int y, int curr, int n) {
  if (dp[x][y][curr] != -1) {
    return dp[x][y][curr];
  }
  for (int i = 0; i < n; i++) {
    if (graph[x][i] >= curr) {
      if (!dfs(y, i, graph[x][i], n)) {
        dp[x][y][curr] = 1;
        return 1;
      }
    }
  }
  dp[x][y][curr] = 0;
  return 0;
}
int main(void) {
  memset(dp, -1, sizeof(dp));
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      graph[i][j] = -1;
    }
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    a--;
    b--;
    graph[a][b] = c - 'a';
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (dfs(i, j, 0, n)) {
        cout << "A";
      } else {
        cout << "B";
      }
    }
    cout << '\n';
  }
}
