#include <bits/stdc++.h>
using namespace std;
vector<pair<int, char> > ad[105];
int dp[105][105][27][2];
int func(int lnode, int rnode, int preVal, int turn) {
  if (turn == 0 && (int)ad[lnode].size() == 0) return 0;
  if (turn == 1 && (int)ad[rnode].size() == 0) return 0;
  if (dp[lnode][rnode][preVal][turn] != -1) {
    return dp[lnode][rnode][preVal][turn];
  }
  int ans = 0;
  if (turn == 0) {
    for (int i = 0; i < (int)ad[lnode].size(); i++) {
      int v = ad[lnode][i].first;
      int curVal = ad[lnode][i].second - 'a';
      if (curVal >= preVal) {
        ans = max(ans, 1 + func(v, rnode, curVal, 1));
      }
    }
  } else {
    for (int i = 0; i < (int)ad[rnode].size(); i++) {
      int v = ad[rnode][i].first;
      int curVal = ad[rnode][i].second - 'a';
      if (curVal >= preVal) {
        ans = min(ans, func(lnode, v, curVal, 0) - 1);
      }
    }
  }
  return dp[lnode][rnode][preVal][turn] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, i, j;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    int u, v;
    char ch;
    cin >> u >> v >> ch;
    ad[u].push_back({v, ch});
  }
  memset(dp, -1, sizeof dp);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      int ans = func(i, j, 0, 0);
      if (ans <= 0)
        cout << "B";
      else
        cout << "A";
    }
    cout << endl;
  }
  return 0;
}
