#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > adj[101];
long long dp[101][101][26];
void func(long long i, long long j, long long c) {
  if (dp[i][j][c] != -1) return;
  dp[i][j][c] = 1;
  for (auto p : adj[i]) {
    if (p.second >= c) {
      func(j, p.first, p.second);
      if (dp[j][p.first][p.second] == 1) dp[i][j][c] = 0;
    }
  }
}
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      for (long long k = 0; k < 26; k++) dp[i][j][k] = -1;
    }
  }
  for (long long i = 0; i < m; i++) {
    long long u, v;
    char ch;
    cin >> u >> v >> ch;
    adj[u].push_back({v, ch - 'a'});
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      func(i, j, 0);
      if (dp[i][j][0] == 0)
        cout << "A";
      else
        cout << "B";
    }
    cout << endl;
  }
}
