#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
int t, n, m;
vector<pair<int, int> > graph[102];
int dp[102][102][27];
int dfs(int u, int v, int c) {
  if (dp[u][v][c] != -1) return dp[u][v][c];
  for (pair<int, int> e : graph[u]) {
    if (e.second >= c) {
      if (!dfs(v, e.first, e.second)) {
        return dp[u][v][c] = 1;
      }
    }
  }
  return dp[u][v][c] = 0;
}
void solve() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int c = 0; c < 26; c++) {
        dp[i][j][c] = -1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cout << (dfs(i, j, 0) == 1 ? "A" : "B");
    }
    cout << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  int u, v;
  char w;
  for (int i = 0; i < m; i++) {
    cin >> u;
    cin >> v;
    cin >> w;
    graph[u].push_back(make_pair(v, w - 'a'));
  }
  solve();
  return 0;
}
