#include <bits/stdc++.h>
using namespace std;
const int N = 102;
vector<pair<int, int> > g[N];
int dp[N][N][26];
int solve(int i, int j, int c) {
  if (dp[i][j][c] != -1) {
    return dp[i][j][c];
  }
  bool ans = false;
  for (auto x : g[i]) {
    int v = x.first, nc = x.second;
    if (nc >= c) {
      ans |= not solve(j, v, nc);
    }
  }
  return dp[i][j][c] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    g[x - 1].push_back({y - 1, c - 'a'});
  }
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << (solve(i, j, 0) ? 'A' : 'B');
    }
    cout << "\n";
  }
}
