#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long MOD = 998244353;
const long long N = 1e2 + 5;
long long n, m, dp[N][N][26];
vector<long long> adj[N], weight[N];
long long is(long long u, long long v, long long W = 0) {
  if (dp[u][v][W] != -1) return dp[u][v][W];
  for (long long i = 0; i < adj[u].size(); i++) {
    long long uv = adj[u][i];
    long long w = weight[u][i];
    if (w >= W) {
      bool okay = is(v, uv, w);
      if (!okay) {
        return dp[u][v][W] = 1;
      }
    }
  }
  return dp[u][v][W] = 0;
}
void solve() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    char w;
    cin >> w;
    adj[x - 1].push_back(y - 1);
    weight[x - 1].push_back(w - 'a');
  }
  memset(dp, -1, sizeof(dp));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      cout << ((is(i, j)) ? "A" : "B");
    }
    cout << "\n";
  }
}
int32_t main() {
  long long t = 1;
  for (long long T = 1; T <= t; T++) {
    solve();
  }
}
