#include <bits/stdc++.h>
using namespace std;
bool visited[101][101][27];
bool dp[101][101][27];
vector<pair<int, int> > g[101];
bool depek(int u, int v, int c) {
  if (visited[u][v][c]) return dp[u][v][c];
  visited[u][v][c] = true;
  bool odp = false;
  for (int i = 0; i < g[u].size(); i++) {
    if (g[u][i].second >= c && !depek(v, g[u][i].first, g[u][i].second))
      odp = true;
  }
  dp[u][v][c] = odp;
  return odp;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int a, b;
  char c;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a, &b);
    cin >> c;
    g[a].push_back({b, c - 'a'});
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (depek(i, j, 0))
        printf("A");
      else
        printf("B");
    }
    printf("\n");
  }
  return 0;
}
