#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
long long gcd(long long x, long long y) {
  return !y ? (long long)abs(x) : gcd(y, x % y);
}
long long lcm(long long a, long long b) {
  return ((long long)abs((a / gcd(a, b)) * b));
}
long long bigmod(long long b, long long p, long long m) {
  if (!p)
    return 1 % m;
  else if (p & 1)
    return (((b % m) + m) % m * bigmod(b, p - 1, m)) % m;
  else {
    long long ret = bigmod(b, p / 2, m);
    return (ret * ret) % m;
  }
}
long long inverse(long long a, long long m) { return bigmod(a, m - 2, m); }
long long extended(long long a, long long m) {
  long long oldr = a, r = m, oldans = 1, ans = 0, quotient;
  while (r) {
    quotient = oldr / r;
    oldr = oldr - r * quotient;
    swap(oldr, r);
    oldans = oldans - ans * quotient;
    swap(oldans, ans);
  }
  return ((oldans % m) + m) % m;
}
template <class t1, class t2>
bool checkBit(t1 &mask, t2 i) {
  return mask & ((t1)1 << i);
}
template <class t1, class t2>
void setBit(t1 &mask, t2 i) {
  mask = mask | ((t1)1 << i);
}
template <class t1, class t2>
void resetBit(t1 &mask, t2 i) {
  mask = mask & ~((t1)1 << i);
}
const long long inf = (long long)1e8;
const long long mod = (long long)1e9 + 7;
vector<pair<int, int> > vec[100 + 5];
int dp[100 + 2][100 + 2][2][30];
bool game(int nowA, int nowB, int p, int last) {
  if (dp[nowA][nowB][p][last] != -1) return dp[nowA][nowB][p][last];
  dp[nowA][nowB][p][last] = 0;
  if (p) {
    for (int i = 0; i < vec[nowA].size() && !dp[nowA][nowB][p][last]; i++) {
      int v = vec[nowA][i].first;
      int c = vec[nowA][i].second;
      if (c >= last) {
        int ret = game(v, nowB, p ^ 1, c) ^ 1;
        if (ret) return dp[nowA][nowB][p][last] = 1;
      }
    }
  } else {
    for (int i = 0; i < vec[nowB].size() && !dp[nowA][nowB][p][last]; i++) {
      int v = vec[nowB][i].first;
      int c = vec[nowB][i].second;
      if (c >= last) {
        int ret = game(nowA, v, p ^ 1, c) ^ 1;
        if (ret) return dp[nowA][nowB][p][last] = 1;
      }
    }
  }
  return dp[nowA][nowB][p][last];
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int u, v;
  char s[5];
  while (m--) {
    scanf("%d %d", &u, &v);
    scanf("%s", s);
    vec[u].push_back(make_pair(v, s[0] - 96));
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (game(i, j, 1, 0))
        printf("A");
      else
        printf("B");
    }
    puts("");
  }
  return 0;
}
