#include <bits/stdc++.h>
using namespace std;
int dp[101][101][28];
vector<pair<int, int> > graph[101];
int fun(int x, int y, int val) {
  if (dp[x][y][val] != -1) return dp[x][y][val];
  for (int i = 0; i < graph[x].size(); i++) {
    if (graph[x][i].second >= val) {
      bool mark = true;
      for (int j = 0; j < graph[y].size(); j++) {
        if (graph[y][j].second >= graph[x][i].second) {
          if (fun(graph[x][i].first, graph[y][j].first, graph[y][j].second) ==
              0) {
            mark = false;
            break;
          }
        }
      }
      if (mark == true) {
        dp[x][y][val] = 1;
        return 1;
      }
    }
  }
  dp[x][y][val] = 0;
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    char d;
    cin >> x >> y >> d;
    graph[x - 1].push_back(make_pair(y - 1, d - 96));
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (fun(i, j, 0))
        cout << "A";
      else
        cout << "B";
    }
    cout << '\n';
  }
}
