#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<vector<pair<int, int> > > adj;
int dp[105][105][27][3];
int dfs(int v, int u, int last, int turn) {
  if (dp[v][u][last][turn]) return dp[v][u][last][turn];
  int cur = ((turn == 1) ? v : u);
  dp[v][u][last][turn] = 3 - turn;
  for (pair<int, int> nei : adj[cur]) {
    if (nei.second >= last) {
      int a = v, b = u;
      if (turn == 1)
        a = nei.first;
      else
        b = nei.first;
      int tmp = dfs(a, b, nei.second, 3 - turn);
      if (tmp == turn) {
        dp[v][u][last][turn] = tmp;
        break;
      }
    }
  }
  return dp[v][u][last][turn];
}
int main() {
  ios::sync_with_stdio(0);
  cin >> N >> M;
  adj.resize(N + 1);
  for (int i = 0; i < M; ++i) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    c = c - 'a' + 1;
    adj[a].push_back(make_pair(b, c));
  }
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      if (i == j)
        cout << 'B';
      else {
        int ans = dfs(i, j, 0, 1);
        cout << (ans == 1 ? 'A' : 'B');
      }
    }
    cout << '\n';
  }
}
