#include <bits/stdc++.h>
using namespace std;
const long long N = 105;
long long n, m;
vector<long long> a[N];
long long f[N][N][26];
char c[N][N];
long long dp(long long u, long long v, long long x) {
  long long res = f[u][v][x];
  if (res >= 0) return res;
  res = 0;
  for (long long i = 0; i < a[u].size(); ++i) {
    long long z = a[u][i];
    long long ch = c[u][z] - 'a';
    if (ch >= x) res |= (dp(v, z, ch) ^ 1);
  }
  return f[u][v][x] = res;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  while (m--) {
    long long x, y;
    cin >> x >> y;
    char ch;
    cin >> ch;
    a[x].push_back(y);
    c[x][y] = ch;
  }
  memset(f, -1, sizeof f);
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j <= n; ++j) {
      if (dp(i, j, 0) == 0)
        cout << "B";
      else
        cout << "A";
    }
    cout << "\n";
  }
}
