#include <bits/stdc++.h>
using namespace std;
vector<string> split(const string& s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) {
    v.emplace_back(x);
  }
  return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << ", ";
  err(++it, args...);
}
vector<pair<int, int>> vt[101];
int dp[101][101][26][2];
bool rec(int u, int v, int ch, int side) {
  if (dp[u][v][ch][side] != -1) return dp[u][v][ch][side];
  int ans = 0;
  if (side) {
    for (auto g : vt[v]) {
      if (g.second >= ch) ans |= !rec(u, g.first, g.second, side ^ 1);
    }
  } else {
    for (auto g : vt[u]) {
      if (g.second >= ch) ans |= !rec(g.first, v, g.second, side ^ 1);
    }
  }
  return dp[u][v][ch][side] = ans;
}
int main() {
  memset(dp, -1, sizeof dp);
  int n, m, i, j, u, v;
  cin >> n >> m;
  char c;
  for (i = 0; i < m; ++i) {
    cin >> u >> v >> c;
    vt[u].push_back({v, c - 'a'});
  }
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= n; ++j) {
      if (rec(i, j, 0, 0))
        printf("A");
      else
        printf("B");
    }
    puts("");
  }
}
