#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > g[110];
char s[2];
int n, m, x, y, f[110][110][27];
int dp(int x, int y, int k) {
  if (f[x][y][k] != 0) return f[x][y][k];
  int ret = 1;
  for (auto e : g[x])
    if (e.second >= k) ret = min(ret, dp(y, e.first, e.second));
  f[x][y][k] = -ret;
  return f[x][y][k];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%s", &x, &y, s);
    g[x].push_back(pair<int, int>(y, s[0] - 'a'));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 0; k < 26; k++) f[i][j][k] = dp(i, j, k);
      if (f[i][j][0] > 0)
        cout << 'A';
      else
        cout << 'B';
    }
    cout << endl;
  }
  return 0;
}
