#include <bits/stdc++.h>
using namespace std;
int n, m;
int A[110][110];
char buf[3];
bool mark[110][110][30][2];
bool memo[110][110][30][2];
bool win(int u, int v, int prev, int turn) {
  bool& ans = memo[u][v][prev][turn];
  if (mark[u][v][prev][turn]) return ans;
  mark[u][v][prev][turn] = true;
  ans = true;
  for (int i = 1; i <= n && ans; i++) {
    if (turn == 0) {
      if (A[u][i] < prev) continue;
      ans = !win(i, v, A[u][i], 1 - turn);
    } else {
      if (A[v][i] < prev) continue;
      ans = !win(u, i, A[v][i], 1 - turn);
    }
  }
  return ans;
}
int main() {
  memset(A, -1, sizeof(A));
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d %s", &x, &y, buf);
    A[x][y] = buf[0] - 'a' + 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (win(i, j, 0, 0))
        printf("B");
      else
        printf("A");
    }
    printf("\n");
  }
  return 0;
}
