#include <bits/stdc++.h>
using namespace std;
const int N = 105;
vector<pair<int, int> > adj[N];
int dp[N][N][26];
int label(char c) { return c - 'a'; }
int go(int u, int v, int lab) {
  int& res = dp[u][v][lab];
  if (res != -1) return res;
  res = 1;
  for (const auto& ed : adj[u]) {
    if (ed.second >= lab) {
      res = min(go(v, ed.first, ed.second) ^ 1, res);
    }
  }
  return res;
}
int32_t main() {
  memset(dp, -1, sizeof dp);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    a--, b--;
    adj[a].push_back({b, label(c)});
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (!go(i, j, 0)) {
        cout << "A";
      } else {
        cout << "B";
      }
    }
    cout << endl;
  }
}
