#include <bits/stdc++.h>
using namespace std;
const long long M = 1e2 + 7, mod = 1e9 + 7;
long long n, m, dp[M][M][28][3];
char W[M][M];
vector<long long> g[M];
long long dfs(long long i, long long j, long long ok, long long c) {
  if (dp[i][j][c][ok] != 0) return dp[i][j][c][ok];
  if (ok == 1 && g[i].size() == 0) {
    dp[i][j][c][ok] = 2;
    return dp[i][j][c][ok];
  }
  if (ok == 2 && g[j].size() == 0) {
    dp[i][j][c][ok] = 1;
    return dp[i][j][c][ok];
  }
  if (ok == 1) {
    long long ck = 2;
    for (auto u : g[i]) {
      if (W[i][u] >= c) {
        if (dfs(u, j, 2, W[i][u]) == 1) {
          ck = 1;
        }
      }
    }
    dp[i][j][c][ok] = ck;
    return dp[i][j][c][ok];
  } else {
    long long ck = 1;
    for (auto u : g[j]) {
      if (W[j][u] >= c) {
        if (dfs(i, u, 1, W[j][u]) == 2) {
          ck = 2;
        }
      }
    }
    dp[i][j][c][ok] = ck;
    return dp[i][j][c][ok];
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  {
    cin >> n >> m;
    for (long long i = 1; i <= m; i++) {
      long long x, y;
      char c;
      cin >> x >> y >> c;
      g[x].push_back(y);
      W[x][y] = c - 'a' + 1;
    }
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= n; j++) {
        if (dfs(i, j, 1, 0) == 1)
          cout << "A";
        else
          cout << "B";
      }
      cout << "\n";
    }
  }
  return 0;
}
