#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 10, M = 2e5 + 100, MOD = 1e9 + 7, MAXN = 1e5 + 10;
const long long inf = 4e18 + 10;
int dp[N][N][30];
vector<pair<int, int> > v[N];
int go(int i, int j, int k) {
  if (dp[i][j][k] != 0) return dp[i][j][k];
  for (int x = 0; x < (int)v[i].size(); x++) {
    if (v[i][x].second >= k) {
      if (go(j, v[i][x].first, v[i][x].second) == 2) {
        dp[i][j][k] = 1;
        return 1;
      }
    }
  }
  dp[i][j][k] = 2;
  return 2;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y, z;
    char c;
    cin >> x >> y >> c;
    z = int(c) - 'a';
    v[x].push_back(make_pair(y, z));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (go(i, j, 0) == 1)
        cout << 'A';
      else
        cout << 'B';
    }
    cout << endl;
  }
}
