#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  char c = getchar();
  int sgn = 1;
  while (c < '0' || c > '9') {
    if (c == '-') sgn = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  x *= sgn;
}
template <typename T>
void out(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) out(x / 10);
  putchar(x % 10 + '0');
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int a[105][105];
int dp[105][105][105];
int n, m;
int dfs(int u, int v, int last) {
  if (dp[u][v][last] != -1) return dp[u][v][last];
  for (int i = 1; i <= n; i++) {
    if (a[u][i] >= last && a[u][i]) {
      int x = dfs(v, i, a[u][i]);
      if (x == 0) return dp[u][v][last] = 1;
    }
  }
  return dp[u][v][last] = 0;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    char z;
    cin >> x >> y >> z;
    a[x][y] = z - 'a' + 1;
  }
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dfs(i, j, 0)) {
        printf("A");
      } else {
        printf("B");
      }
    }
    cout << endl;
  }
  return 0;
}
