#include <bits/stdc++.h>
using namespace std;
const int N = 105;
struct node {
  int to, v;
};
vector<node> edge[N];
int dp[N][N][30];
bool check(int x, int y, int la) {
  if (~dp[x][y][la]) return dp[x][y][la];
  for (int i = 0; i < edge[x].size(); i++) {
    int to = edge[x][i].to, z = edge[x][i].v;
    if (z < la) continue;
    if (!check(y, to, z)) return dp[x][y][la] = 1;
  }
  return dp[x][y][la] = 0;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1, u, v; i <= m; i++) {
    char s[2];
    scanf("%d%d%s", &u, &v, s);
    int tmp = s[0] - 'a' + 1;
    edge[u].push_back(node<% v, tmp %>);
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (check(i, j, 0))
        cout << 'A';
      else
        cout << 'B';
    cout << endl;
  }
  return 0;
}
