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