#include <bits/stdc++.h>
using namespace std;
int dp[110][110][28][2];
vector<int> vc[110], wt[110];
int rec(int x, int y, int pre, int mv) {
  int &ret = dp[x][y][pre][mv];
  if (ret != -1) return ret;
  ret = 0;
  if (mv == 1) {
    for (int i = 0; i < vc[x].size(); i++) {
      int v = vc[x][i];
      if (wt[x][i] >= pre) ret |= (1 - rec(v, y, wt[x][i], 2));
    }
  } else {
    for (int i = 0; i < vc[y].size(); i++) {
      int v = vc[y][i];
      if (wt[y][i] >= pre) ret |= (1 - rec(x, v, wt[y][i], 1));
    }
  }
  return ret;
}
int main() {
  int n, m, u, v;
  char ch;
  memset(dp, -1, sizeof dp);
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %c", &u, &v, &ch);
    vc[u].push_back(v);
    wt[u].push_back(ch - 'a' + 1);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (rec(i, j, 0, 1))
        printf("A");
      else
        printf("B");
    }
    printf("\n");
  }
}
