#include <bits/stdc++.h>
using namespace std;
int dp[103][103][28];
int visited[103][103][28];
int Graph[103][103];
int Nv, Ne;
bool dfs(int x, int y, int weight) {
  if (visited[x][y][weight]) return dp[x][y][weight];
  int f = 0;
  for (int i = 1; i <= Nv; i++) {
    if (!Graph[x][i] || Graph[x][i] < weight) continue;
    if (dfs(y, i, Graph[x][i]) == 0) {
      f = 1;
      break;
    }
  }
  visited[x][y][weight] = 1;
  dp[x][y][weight] = f;
  return f;
}
int main() {
  int a, b;
  char c;
  cin >> Nv >> Ne;
  for (int i = 0; i < Ne; i++) {
    cin >> a >> b >> c;
    Graph[a][b] = c - 'a' + 1;
  }
  for (int i = 1; i <= Nv; i++) {
    for (int j = 1; j <= Nv; j++) {
      if (dfs(i, j, 0))
        cout << 'A';
      else
        cout << 'B';
    }
    if (i < Nv) cout << '\n';
  }
}
