#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int INF = 1e9 + 7;
const int N = 1e2 + 7;
const int M = 1e6 + 7;
int dp[N][N][30];
struct edge {
  int to, w;
  edge(int to = 0, int w = 0) : to(to), w(w) {}
};
vector<edge> G[N];
bool dfs(int x, int y, int lim) {
  if (dp[x][y][lim] != -1) return dp[x][y][lim];
  dp[x][y][lim] = 0;
  for (int i = 0; i < G[x].size(); i++) {
    int v = G[x][i].to, w = G[x][i].w;
    if (w < lim) continue;
    if (!dfs(y, v, w)) return dp[x][y][lim] = 1;
  }
  return 0;
}
signed main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= m; i++) {
    int u, v;
    char w;
    cin >> u >> v >> w;
    G[u].push_back(edge(v, w - 'a'));
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (dfs(i, j, 0))
        cout << "A";
      else
        cout << "B";
      if (j == n) cout << "\n";
    }
  return 0;
}
