#include <bits/stdc++.h>
using namespace std;
const long long N = 102;
vector<pair<long long, long long>> g[N];
long long viz[N][N][28];
long long n, m;
long long win(long long a, long long b, long long last) {
  if (viz[a][b][last] != -1) return viz[a][b][last];
  for (auto it : g[a]) {
    if (it.second >= last && !win(b, it.first, it.second)) {
      viz[a][b][last] = 1;
      return 1;
    }
  }
  viz[a][b][last] = 0;
  return 0;
}
int32_t main() {
  cin >> n >> m;
  for (long long i = 1; i <= m; ++i) {
    long long x, y;
    char ch;
    cin >> x >> y >> ch;
    g[x].emplace_back(y, ch - 'a' + 1);
  }
  memset(viz, -1, sizeof viz);
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j <= n; ++j) {
      long long eval = win(i, j, 0);
      if (eval == 1)
        cout << "A";
      else
        cout << "B";
    }
    cout << '\n';
  }
}
