#include <bits/stdc++.h>
using namespace std;
const int N = 101;
char winner_table[N][N][26];
vector<pair<int, int>> graph[N];
char get_winner(int u, int v, int char_to_beat) {
  if (!winner_table[u][v][char_to_beat]) {
    char winner = 'B';
    for (const auto& edges : graph[u]) {
      if (edges.second >= char_to_beat &&
          get_winner(v, edges.first, edges.second) == 'B') {
        winner = 'A';
        break;
      }
    }
    winner_table[u][v][char_to_beat] = winner;
  }
  return winner_table[u][v][char_to_beat];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int v, u;
    char c;
    cin >> v >> u >> c;
    graph[v - 1].emplace_back(u - 1, c - 'a');
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cout << get_winner(i, j, 0);
    }
    cout << '\n';
  }
}
