#include <bits/stdc++.h>
using namespace std;
const long long N = 1e2 + 55, mod = 1e9 + 7;
long long dp[N][N][200];
vector<long long> v[N];
char gg[N][N];
long long go(long long x, long long y, char ch) {
  long long i, j, k, f;
  k = ch;
  if (dp[x][y][k] != -1) return dp[x][y][k];
  for (i = 0; i < v[x].size(); i++) {
    j = v[x][i];
    if (gg[x][j] >= ch) {
      f = go(y, j, gg[x][j]);
      if (f == 0) {
        return dp[x][y][k] = 1;
      }
    }
  }
  return dp[x][y][k] = 0;
}
int main() {
  long long n, m, i, j, k, a, b, c, x, y, z;
  char ch;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> x >> y >> ch;
    gg[x][y] = ch;
    v[x].push_back(y);
  }
  memset(dp, -1, sizeof(dp));
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      k = go(i, j, 'a');
      if (k == 1) {
        cout << "A";
      } else {
        cout << "B";
      }
    }
    cout << "\n";
  }
}
