#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int dr8[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dc8[] = {1, -1, 0, 0, -1, 1, -1, 1};
int dr4[] = {0, 1, -1, 0};
int dc4[] = {1, 0, 0, -1};
vector<pair<int, char> > gr[N];
int vis[N];
int dp[N][N][30];
int dfs(int u, int v, int c) {
  if (dp[u][v][c] != -1) return dp[u][v][c];
  int f = 0;
  for (int i = 0; i < gr[u].size(); i++) {
    pair<int, char> p = gr[u][i];
    int vv = p.first;
    char ch = p.second;
    if (c <= (ch - 'a')) {
      if (dfs(v, vv, (ch - 'a')) == 0) f = 1;
    }
  }
  return dp[u][v][c] = f;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int x, y, n, m;
  char c;
  memset(dp, -1, sizeof dp);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> c;
    gr[x].push_back({y, c});
  }
  for (int i = 1; i <= n; i++) {
    if (gr[i].size() == 0) {
      for (int j = 0; j < 26; j++) dp[i][i][j] = 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cout << (dfs(i, j, 0) == 1 ? 'A' : 'B');
    }
    cout << "\n";
  }
}
