#include <bits/stdc++.h>
using namespace std;
const long long NMAX = 110;
vector<vector<pair<long long, long long> > > g;
long long dp[NMAX][NMAX][26];
long long get(long long v, long long u, long long last) {
  if (last != -1 && dp[v][u][last]) return dp[v][u][last];
  bool ok = false;
  for (long long i = 0; i < g[v].size(); i++) {
    long long to = g[v][i].first, nxt = g[v][i].second;
    if (nxt < last) continue;
    ok |= (get(u, to, nxt) == 2);
  }
  if (last != -1 && ok) dp[v][u][last] = 1;
  if (last != -1 && !ok) dp[v][u][last] = 2;
  if (ok)
    return 1;
  else
    return 2;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  g.resize(n);
  for (long long i = 0; i < m; i++) {
    long long a, b;
    char c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a].push_back({b, c - 'a'});
  }
  vector<vector<long long> > ans(n, vector<long long>(n));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      ans[i][j] = get(i, j, -1);
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      cout << (ans[i][j] == 1 ? 'A' : 'B');
    }
    cout << '\n';
  }
  return 0;
}
