#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> graph;
int weight[101][101], win[101][101][2][27];
int dfs(int a, int b, int chance, int pre) {
  if (win[a][b][chance][pre] != -1) return win[a][b][chance][pre];
  win[a][b][chance][pre] = 0;
  for (int i = 0; i < graph[a].size(); i++) {
    if (weight[a][graph[a][i]] >= pre)
      if (dfs(b, graph[a][i], (chance ^ 1), weight[a][graph[a][i]]) == 0) {
        win[a][b][chance][pre] = 1;
        break;
      }
  }
  return win[a][b][chance][pre];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  graph.assign(n + 1, vector<int>());
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      for (int k = 0; k <= 26; k++) win[i][j][0][k] = -1, win[i][j][1][k] = -1;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    graph[a].push_back(b);
    weight[a][b] = c - 'a' + 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dfs(i, j, 0, 0) == 1)
        cout << "A";
      else
        cout << "B";
    }
    cout << endl;
  }
}
