#include <bits/stdc++.h>
using namespace std;
const int N = 101;
int e[N][N], f[N][N][2][30], n;
int dfs(int suck, int fuck, int dan, int c) {
  int &azibint = f[suck][fuck][dan][c];
  if (azibint != -1) return azibint;
  azibint = 0;
  if (dan == 0) {
    for (int v = 1; v <= n; ++v) {
      if (e[suck][v] >= c)
        azibint = max(azibint, 1 - dfs(v, fuck, 1 - dan, e[suck][v]));
    }
  } else {
    for (int v = 1; v <= n; ++v) {
      if (e[fuck][v] >= c)
        azibint = max(azibint, 1 - dfs(suck, v, 1 - dan, e[fuck][v]));
    }
  }
  return azibint;
}
int main() {
  memset(f, -1, sizeof f);
  for (int i = 0; i < 101; i++)
    for (int j = 0; j < 101; j++) e[i][j] = -1;
  int m;
  cin >> n >> m;
  int suck, fuck;
  char t;
  for (int i = 1; i <= m; ++i) {
    cin >> suck >> fuck >> t;
    e[suck][fuck] = max(e[suck][fuck], int(t - 'a'));
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (dfs(i, j, 0, 0))
        cout << 'A';
      else
        cout << 'B';
    }
    cout << endl;
  }
  return 0;
}
