#include <bits/stdc++.h>
using namespace std;
vector<pair<int, char>> adj[105];
int dp[105][105][2][124];
bool dfs(int a, int b, bool x, int prv) {
  bool pl = false;
  if (dp[a][b][int(x)][prv] != -1) return bool(dp[a][b][int(x)][prv]);
  if (x) {
    for (int i = 0; i < adj[a].size(); i++) {
      if (int(adj[a][i].second) >= prv) {
        pl = pl || (!dfs(adj[a][i].first, b, !x, adj[a][i].second));
      }
    }
  } else {
    for (int i = 0; i < adj[b].size(); i++) {
      if (int(adj[b][i].second) >= prv) {
        pl = pl || (!dfs(a, adj[b][i].first, !x, adj[b][i].second));
      }
    }
  }
  dp[a][b][int(x)][prv] = pl;
  return pl;
}
int main() {
  std::ios::sync_with_stdio(false);
  ;
  int n, m;
  std::cin >> n >> m;
  for (int i = 0; i < 105; i++) {
    for (int j = 0; j < 105; j++) {
      for (int z = 0; z < 2; z++) {
        for (int nm = 0; nm < 123; nm++) {
          dp[i][j][z][nm] = -1;
        }
      }
    }
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    char ch;
    std::cin >> u >> v;
    std::cin >> ch;
    adj[u].push_back(make_pair(v, ch));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dfs(i, j, true, 0))
        std::cout << "A";
      else
        std::cout << "B";
    }
    std::cout << endl;
  }
  return 0;
}
