#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
long long ipow(long long base, long long exp) {
  if (exp == 0) return 1ll * 1;
  long long result = 1;
  for (;;) {
    if (exp & 1) {
      result *= base;
      result = result % 10000000;
    }
    exp >>= 1;
    if (!exp) break;
    base *= base;
    base = base % 10000000;
  }
  return result % 10000000;
}
int dp[101][101][26];
vector<pair<int, int> > A[101];
int dfs(int mx, int lucas, int ch) {
  if (dp[mx][lucas][ch] != -1) return dp[mx][lucas][ch];
  for (int i = 0; i < A[mx].size(); i++) {
    int mx1 = A[mx][i].first;
    int newch = A[mx][i].second;
    if (newch >= ch && !dfs(lucas, mx1, newch)) return dp[mx][lucas][ch] = 1;
  }
  return dp[mx][lucas][ch] = 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  auto start = high_resolution_clock::now();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    A[a].push_back({b, c - 'a'});
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dfs(i, j, 0)) {
        cout << "A";
      } else {
        cout << "B";
      }
    }
    cout << endl;
  }
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start);
}
