#include <bits/stdc++.h>
using namespace std;
int n, m, u, v;
int dp[107][107][27];
char c;
vector<pair<int, int> > edge[107];
int solve(int x, int y, int cur) {
  if (dp[x][y][cur] != -1) return dp[x][y][cur];
  if ((int)edge[x].size() == 0) return dp[x][y][cur] = 0;
  dp[x][y][cur] = 0;
  for (auto v : edge[x]) {
    int to = v.first;
    int val = v.second;
    if (val < cur)
      continue;
    else
      dp[x][y][cur] = max(dp[x][y][cur], solve(y, to, val) ^ 1);
  }
  return dp[x][y][cur];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> u >> v >> c;
    int val = c - 'a' + 1;
    edge[u].push_back(make_pair(v, val));
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int res = solve(i, j, 1);
      if (res == 1)
        cout << "A";
      else
        cout << "B";
    }
    cout << "\n";
  }
}
