#include <bits/stdc++.h>
using namespace std;
const int Max = 100 + 10;
const int Mod = 1e9 + 7;
const long long int Inf = 1LL << 62;
int dx4[] = {0, 0, -1, 1};
int dy4[] = {1, -1, 0, 0};
int dx[] = {1, 1, 1, 0, 0, -1, -1, -1};
int dy[] = {1, 0, -1, 1, -1, 1, 0, -1};
vector<long long int> vec[Max];
long long int dp[Max][Max][2 * Max];
long long int cost[Max][Max];
long long int rec(long long int u, long long int v, long long int ch) {
  long long int &ret = dp[u][v][ch];
  if (~ret) return ret;
  ret = 0;
  for (long long int x : vec[u]) {
    if (ch <= cost[u][x]) {
      ret |= !rec(v, x, cost[u][x]);
    }
  }
  return ret;
}
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
  };
  memset(dp, -1, sizeof(dp));
  long long int n, m, k, q, t, cnt = 0, sum = 0, mx = -Inf, mn = Inf;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    long long int u, v;
    char ch;
    cin >> u >> v >> ch;
    cost[u][v] = ch - 'a';
    vec[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      bool res = rec(i, j, 0);
      if (res) {
        cout << ("A");
      } else {
        cout << ("B");
      }
    }
    cout << endl;
  }
  return 0;
}
