#include <bits/stdc++.h>
using namespace std;
int dat[105][105];
vector<int> grf[105];
int dp[2][105][105][30];
int fun(int trn, int apos, int bpos, int c) {
  int& ret = dp[trn][apos][bpos][c];
  if (ret != -1) return ret;
  if (trn == 0) {
    bool ok = 0;
    for (int i = 0; i < grf[apos].size(); i++) {
      int now = grf[apos][i];
      int val = dat[apos][now];
      if (val >= c) {
        int vvv = fun(1, now, bpos, val);
        if (vvv == 1) ok = 1;
      }
    }
    if (ok)
      ret = 1;
    else
      ret = 2;
  }
  if (trn == 1) {
    bool ok = 0;
    for (int i = 0; i < grf[bpos].size(); i++) {
      int now = grf[bpos][i];
      int val = dat[bpos][now];
      if (val >= c) {
        int vvv = fun(0, apos, now, val);
        if (vvv == 2) ok = 1;
      }
    }
    if (ok)
      ret = 2;
    else
      ret = 1;
  }
  return ret;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    dat[a][b] = (c - 'a') + 1;
    grf[a].push_back(b);
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int ans = fun(0, i, j, 0);
      if (ans == 1)
        cout << 'A';
      else if (ans == 2)
        cout << 'B';
    }
    cout << endl;
  }
  return 0;
}
