#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, char> > > adj(105);
int dp[105][105][2][26];
int dfs(int i, int j, int chnce, char ch) {
  if (dp[i][j][chnce][ch - 'a'] != -1)
    return dp[i][j][chnce][ch - 'a'];
  else {
    int m = 0;
    if (chnce == 0) {
      m = 1;
      for (auto mv : adj[i]) {
        if (mv.second >= ch) m = min(dfs(mv.first, j, 1 - chnce, mv.second), m);
        if (m == 0) break;
      }
    } else {
      for (auto mv : adj[j]) {
        if (mv.second >= ch) m = max(dfs(i, mv.first, 1 - chnce, mv.second), m);
        if (m == 1) break;
      }
    }
    return (dp[i][j][chnce][ch - 'a'] = m);
  }
}
signed main() {
  ;
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int t = 1;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int u, v;
    char w;
    for (int i = 0; i < m; i++) {
      cin >> u >> v >> w;
      adj[u].push_back(make_pair(v, w));
    }
    memset(dp, -1, sizeof(dp));
    for (int i = 1; i <= n; i++) {
      for (int k = 0; k < 26; k++) {
        dp[i][i][1][k] = 0;
        dp[i][i][0][k] = 1;
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        dfs(i, j, 0, 'a');
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (dp[i][j][0][0] == 1)
          cout << "B";
        else
          cout << "A";
      }
      cout << '\n';
    }
  };
}
