#include <bits/stdc++.h>
using namespace std;
int dp[110][110][30];
int head[110];
int cnt;
struct edge {
  int to, next, x;
};
edge arr[20000];
void add(int u, int v, int w) {
  arr[cnt].to = v;
  arr[cnt].x = w;
  arr[cnt].next = head[u];
  head[u] = cnt++;
}
int calc(int u, int v, int a) {
  if (dp[u][v][a] != -1) return dp[u][v][a];
  for (int i = head[u]; ~i; i = arr[i].next) {
    int b = arr[i].x;
    if (b >= a) {
      if (!calc(v, arr[i].to, b)) return dp[u][v][a] = 1;
    }
  }
  return dp[u][v][a] = 0;
}
int main() {
  int n, m, u, v;
  char c;
  memset(dp, -1, sizeof(dp));
  memset(head, -1, sizeof(head));
  cnt = 0;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> c;
    add(u, v, c - 'a');
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cout << (calc(i, j, 0) ? 'A' : 'B');
    }
    cout << endl;
  }
}
