#include <bits/stdc++.h>
using namespace std;
int dp[105][105][27][2];
vector<pair<int, char>> adj[105];
bool fun(int a, int b, int c, int d) {
  if (dp[a][b][c][d] != -1) return dp[a][b][c][d];
  if (d == 0) {
    bool ret = 0;
    for (int i = 0; i < adj[a].size(); i++) {
      if (adj[a][i].second - 'a' >= c)
        if (fun(adj[a][i].first, b, adj[a][i].second - 'a', 1 - d))
          return dp[a][b][c][d] = 1;
    }
    return dp[a][b][c][d] = 0;
  }
  bool ret = 0;
  for (int i = 0; i < adj[b].size(); i++) {
    if (adj[b][i].second - 'a' >= c)
      if (fun(a, adj[b][i].first, adj[b][i].second - 'a', 1 - d) == 0)
        return dp[a][b][c][d] = 0;
  }
  return dp[a][b][c][d] = 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  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;
    adj[u].push_back({v, w});
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (fun(i, j, 0, 0))
        cout << "A";
      else
        cout << "B";
    }
    cout << endl;
  }
  return 0;
}
