#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
int N, M, sg[MAXN][MAXN][30];
struct edge {
  int t, kw;
};
vector<edge> adj[MAXN];
bool dfs(int x, int y, int kw) {
  if (sg[x][y][kw] != -1) return sg[x][y][kw];
  sg[x][y][kw] = 0;
  for (int i = 0; i < adj[x].size(); i++) {
    if (adj[x][i].kw < kw) continue;
    if (dfs(y, adj[x][i].t, adj[x][i].kw) == 0) return sg[x][y][kw] = 1;
  }
  return sg[x][y][kw] = 0;
}
int main() {
  int x, y;
  char kw;
  for (int i = 0; i < MAXN; i++)
    for (int j = 0; j < MAXN; j++)
      for (int k = 0; k < 30; k++) sg[i][j][k] = -1;
  cin >> N >> M;
  for (int i = 1; i <= M; i++) {
    cin >> x >> y >> kw;
    adj[x].push_back(edge{y, kw - 'a'});
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      if (dfs(i, j, 0))
        cout << 'A';
      else
        cout << 'B';
    }
    cout << endl;
  }
  return 0;
}
