#include <bits/stdc++.h>
using namespace std;
int n, m, d[105][105][3][30];
char ta[5];
vector<int> a[105], b[105];
int f(int p, int q, int w, int num) {
  int i, z, t, wi = 0;
  if (d[p][q][w][num] != 0) return d[p][q][w][num];
  if (w == 1)
    z = p;
  else
    z = q;
  for (i = 0; i < a[z].size(); i++) {
    if (b[z][i] < num) continue;
    if (w == 1)
      t = f(a[z][i], q, 3 - w, b[z][i]);
    else
      t = f(p, a[z][i], 3 - w, b[z][i]);
    if (t == w) {
      wi = 1;
      break;
    }
  }
  if (wi)
    return d[p][q][w][num] = w;
  else
    return d[p][q][w][num] = 3 - w;
}
int main() {
  int i, j, t1, t2;
  cin >> n >> m;
  while (m--) {
    scanf("%d %d %s", &t1, &t2, ta);
    a[t1].push_back(t2);
    b[t1].push_back(ta[0] - 'a');
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      if (f(i, j, 1, 0) == 1)
        printf("A");
      else
        printf("B");
    }
    puts("");
  }
  return 0;
}
