#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
long long gcdExtended(long long a, long long b, long long *x, long long *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
long long modInverse(long long a, long long m) {
  long long x, y;
  long long g = gcdExtended(a, m, &x, &y);
  if (g != 1)
    return -1;
  else {
    long long res = (x % m + m) % m;
    return res;
  }
}
long long fast(long long x) {
  if (x == 0) return 1;
  if (x == 1) return 2;
  long long y = fast(x / 2);
  if (x % 2 == 0) {
    return y * y;
  }
  return y * y * 2;
}
long long gcd(long long a, long long b) {
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
bool win(vector<vector<vector<int>>> &dp, vector<vector<pair<int, int>>> &graph,
         int x, int y, int curr) {
  if (dp[x][y][curr] != 0) {
    if (dp[x][y][curr] == 1) return true;
    return false;
  }
  for (auto p : graph[x]) {
    if (p.second >= curr && !win(dp, graph, y, p.first, p.second)) {
      dp[x][y][curr] = 1;
      return true;
    }
  }
  dp[x][y][curr] = -1;
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int>>> graph(n, vector<pair<int, int>>());
  for (int i = 0; i < m; i++) {
    int u, v;
    char w;
    cin >> u >> v >> w;
    graph[u - 1].push_back(make_pair(v - 1, w - 'a'));
  }
  vector<string> sol(n, string(n, 'C'));
  vector<vector<vector<int>>> dp(n, vector<vector<int>>(n, vector<int>(26, 0)));
  for (int i = 0; i < n; i++) {
    sol[i][i] = 'B';
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (sol[i][j] != 'C') continue;
      if (win(dp, graph, i, j, 0)) {
        sol[i][j] = 'A';
      } else {
        sol[i][j] = 'B';
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << sol[i] << endl;
  }
  return 0;
}
