#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 5;
int n, m;
int a[N][N];
char b[N];
int dp[N][N][30][2];
int f(int x, int y, int last, int turn) {
  int &r = dp[x][y][last][turn];
  if (r != -1) return r;
  r = 0;
  if (turn == 0) {
    for (int i = 1; i <= n; i++)
      if (a[x][i] and a[x][i] >= last and !f(i, y, a[x][i], !turn)) {
        r = 1;
        break;
      }
  } else {
    for (int i = 1; i <= n; i++)
      if (a[y][i] and a[y][i] >= last and !f(x, i, a[y][i], !turn)) {
        r = 1;
        break;
      }
  }
  return r;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    char c;
    scanf("%d %d %c", &x, &y, &c);
    a[x][y] = c - 'a' + 1;
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) b[j] = 'B' - f(i, j, 0, 0);
    puts(b + 1);
  }
  return 0;
}
