#include <bits/stdc++.h>
using namespace std;
template <class T>
int size(const T &x) {
  return x.size();
}
const int INF = ~(1 << 31);
const double pi = acos(-1);
const double EPS = 1e-9;
int memo[120][120][30][3];
vector<pair<int, int> > edg[120];
int dp(int at1, int at2, int last, int turn) {
  if (memo[at1][at2][last][turn] != -1) return memo[at1][at2][last][turn];
  int ans = INF;
  if (turn == 1) {
    for (auto it = (edg[at1]).begin(); it != (edg[at1]).end(); ++it) {
      if (it->second >= last) {
        ans = min(dp(it->first, at2, it->second, 0), ans);
      }
    }
    if (ans == INF)
      return 1;
    else
      return memo[at1][at2][last][turn] = ans;
  } else if (turn == 0) {
    ans = -INF;
    for (auto it = (edg[at2]).begin(); it != (edg[at2]).end(); ++it) {
      if (it->second >= last) {
        ans = max(dp(at1, it->first, it->second, 1), ans);
      }
    }
    if (ans == -INF)
      return 0;
    else
      return memo[at1][at2][last][turn] = ans;
  }
  return memo[at1][at2][last][turn] = ans;
}
int main() {
  cin.sync_with_stdio(false);
  memset(memo, -1, sizeof(memo));
  int n, m;
  cin >> n >> m;
  for (int i = (0); i < (m); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    char c;
    cin >> c;
    int _c = c - 'a' + 1;
    edg[a].push_back(pair<int, int>(b, _c));
  }
  for (int i = (0); i < (n); i++) {
    for (int j = (0); j < (n); j++) {
      cout << (dp(i, j, 0, 1) == 1 ? 'B' : 'A');
    }
    cout << endl;
  }
  return 0;
}
