#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
inline long long sbt(long long x) { return __builtin_popcountll(x); }
inline long long iceil(double a) { return (long long)(ceil(a)); }
inline long long mul(long long a, long long b,
                     long long m = (long long)(1e9 + 7)) {
  return ((a % m) * (b % m)) % m;
}
inline long long add(long long a, long long b,
                     long long m = (long long)(1e9 + 7)) {
  return (a + b) % m;
}
inline long long sub(long long a, long long b,
                     long long m = (long long)(1e9 + 7)) {
  return (a - b + m) % m;
}
long long fastpow(long long a, long long b,
                  long long m = (long long)(1e9 + 7)) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = mul(res, a, m);
    a = mul(a, a, m);
    b >>= 1;
  }
  return res;
}
long long modinv(long long a, long long m = (long long)(1e9 + 7)) {
  return fastpow(a, m - 2, m);
}
long long n, m;
vector<pair<long long, long long> > adj[110];
long long dp[110][110][27];
long long solve(long long i, long long j, long long c) {
  if (dp[i][j][c] != -1) return dp[i][j][c];
  for (auto k : adj[i]) {
    if (k.second >= c) {
      if (!solve(j, k.first, k.second)) {
        return dp[i][j][c] = 1;
      }
    }
  }
  return dp[i][j][c] = 0;
}
void get_ac() {
  cin >> n >> m;
  memset(dp, -1, sizeof(dp));
  long long a, b;
  char c;
  for (long i = 0; i < m; i++) {
    cin >> a >> b >> c;
    adj[a].push_back({b, c - 'a' + 1});
  }
  for (auto i = 1; i <= n; i++) {
    for (auto j = 1; j <= n; j++) {
      if (solve(i, j, 0) == 1)
        cout << "A";
      else
        cout << "B";
    }
    cout << "\n";
  }
}
int main() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  cin.tie(NULL);
  {
    get_ac();
    cout << "\n";
  }
  return 0;
}
