#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 << '\t';
  err(++it, args...);
}
const long double eps = 1e-9;
const long long mod = 1e9 + 7;
pair<long long, long long> dir[8] = {{-1, 0}, {1, 0},   {0, -1}, {0, 1},
                                     {1, 1},  {-1, -1}, {-1, 1}, {1, -1}};
const long long nn = 105;
vector<pair<long long, long long> > g[nn];
long long dp[nn][nn][30];
long long fun(long long i, long long j, long long cur) {
  if (((long long)(g[i]).size()) == 0) return dp[i][j][cur] = 0;
  if (dp[i][j][cur] != -1) return dp[i][j][cur];
  for (auto p : g[i]) {
    long long v = p.first, x = p.second;
    if (x >= cur) {
      long long can_win = fun(j, v, x);
      if (!can_win) return dp[i][j][cur] = 1;
    }
  }
  return dp[i][j][cur] = 0;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; ++i) {
    long long u, v;
    char c;
    cin >> u >> v >> c;
    long long x = c - 'a' + 1;
    g[u].emplace_back(v, x);
  }
  for (long long i = 1; i <= n; i++) {
    memset(dp, -1, sizeof dp);
    string s;
    for (long long j = 1; j <= n; j++) {
      if (fun(i, j, 0))
        s += 'A';
      else
        s += 'B';
    }
    cout << s << '\n';
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long T = 1;
  for (long long tc = 1; tc <= T; tc++) {
    solve();
  }
  return 0;
}
