#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
class Edge {
 public:
  int letter, vID;
  Edge(int vID, int letter) : letter(letter), vID(vID) {}
};
class Solution {
 public:
  int n, m;
  vector<vector<int>> gameStats;
  vector<vector<Edge>> G;
  Solution() {
    cin >> n >> m;
    gameStats = vector<vector<int>>(n, vector<int>(n, -1));
    G = vector<vector<Edge>>(n, vector<Edge>());
  }
  void readGarph();
  int simulateGameForPair(int u, int v);
  void simulateGemes();
};
void Solution::readGarph() {
  int u, v;
  char c;
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> c;
    G[(u - 1)].emplace_back((v - 1), c);
  }
}
int Solution::simulateGameForPair(int u, int v) {
  if (gameStats[u][v] != -1) {
    return gameStats[u][v];
  }
  if (G[u].empty()) {
    gameStats[u][v] = -2;
    return -2;
  }
  int maxCharOfWinPath = -2;
  bool winner;
  for (auto edgeUp : G[u]) {
    winner = true;
    for (auto edgeVp : G[v]) {
      if (edgeVp.letter < edgeUp.letter) {
        continue;
      }
      if (simulateGameForPair(edgeUp.vID, edgeVp.vID) <
          max(edgeUp.letter, edgeVp.letter)) {
        winner = false;
        break;
      }
    }
    if (winner) {
      maxCharOfWinPath = max(maxCharOfWinPath, edgeUp.letter);
    }
  }
  gameStats[u][v] = maxCharOfWinPath;
  return maxCharOfWinPath;
}
void Solution::simulateGemes() {
  for (int j = 0; j < n; j++) {
    for (int i = 0; i < n; i++) {
      if (simulateGameForPair(j, i) > 0) {
        cout << "A";
      } else {
        cout << "B";
      }
    }
    cout << endl;
  }
}
int main() {
  Solution solution;
  solution.readGarph();
  solution.simulateGemes();
  return 0;
}
