#include <bits/stdc++.h>
using namespace std;
long long in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline void read(long long *a, long long n) {
  for (long long i = 0; i < n; i++) a[i] = in();
}
inline void readL(long long *a, long long n) {
  for (long long i = 0; i < n; i++) a[i] = lin();
}
const long long maxn = 100 + 10;
const long long mod = 1e9 + 7;
const long long MAX_VAL = 1e18 + 10;
const long long MAGIC = 350;
long long n, m;
vector<pair<long long, long long> > g[maxn];
long long dp[maxn][maxn][27];
long long ret[maxn][maxn];
inline long long dfs(long long a, long long b, long long pre) {
  if (pre >= 26) return 1;
  if (dp[a][b][pre] + 1) return dp[a][b][pre];
  for (auto u : g[a]) {
    if (u.second >= pre) {
      long long getRes = dfs(b, u.first, u.second);
      if (getRes == 1) return dp[a][b][pre] = 0;
    }
  }
  return dp[a][b][pre] = 1;
}
int32_t main() {
  n = in(), m = in();
  memset(dp, -1, sizeof dp);
  for (long long i = 0; i < m; i++) {
    long long v = in() - 1, u = in() - 1;
    char ch;
    do {
      ch = getchar();
    } while (!isalpha(ch));
    g[v].push_back({u, ch - 'a'});
  }
  for (long long a = 0; a < n; a++, cout << "\n") {
    for (long long b = 0; b < n; b++) {
      ret[a][b] = dfs(a, b, 0);
      if (ret[a][b] == 0)
        cout << "A";
      else
        cout << "B";
    }
  }
}
