#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 2e2 + 4;
vector<pair<int, int>> v[N];
int ma[N][N][68];
int solve(int a, int b, int ch) {
  int node = a;
  assert(ch < 30);
  if (ma[a][b][ch] != -1) return ma[a][b][ch];
  int here = 0;
  for (auto it : v[node]) {
    if (ch > it.second) continue;
    here |= (!solve(b, it.first, it.second));
  }
  ma[a][b][ch] = here;
  return here;
}
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  memset(ma, -1, sizeof(ma));
  for (int i = 0; i < m; i++) {
    int a, b;
    char ch;
    scanf("%d", &a);
    scanf("%d", &b);
    cin >> ch;
    v[a].push_back(make_pair(b, (int)(ch - 'a') + 1));
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < n + 1; j++)
      if (solve(i, j, 0))
        printf("A");
      else
        printf("B");
    printf("\n");
  }
  return 0;
}
