#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
long long int power(long long int base, long long int exp) {
  long long int res = 1;
  while (exp) {
    if (exp % 2) res *= base;
    base *= base;
    res %= mod;
    base %= mod;
    exp /= 2;
  }
  return res;
}
vector<pair<int, int> > adj[maxn];
int dp[2][26][105][105];
int go(int m, int l, int pos, bool curr) {
  int &ret = dp[curr][pos][m][l];
  if (ret != -1) return ret;
  if (curr) {
    ret = 0;
    for (auto j : adj[m]) {
      if (j.second >= pos) {
        ret |= go(j.first, l, j.second, !curr);
      }
      if (ret) break;
    }
  } else {
    ret = 1;
    for (auto j : adj[l]) {
      if (j.second >= pos) {
        ret &= go(m, j.first, j.second, !curr);
      }
      if (!ret) break;
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, i, u, v, j;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    char c;
    cin >> u >> v >> c;
    adj[u].push_back({v, c - 'a'});
  }
  memset(dp, -1, sizeof(dp));
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      go(i, j, 0, 1);
      if (dp[1][0][i][j] == 1) {
        cout << "A";
      } else {
        cout << "B";
      }
    }
    cout << "\n";
  }
  return 0;
}
