#include <bits/stdc++.h>
using namespace std;
vector<int> v[200], c[200];
int dp[102][102][26][2];
int func(int a, int b, int last, int curr) {
  int i;
  int &ans = dp[a][b][last][curr];
  if (ans != -1) return ans;
  if (curr == 0) {
    ans = 0;
    for (i = 0; i < v[a].size(); i++) {
      if (c[a][i] < last) continue;
      int k = func(v[a][i], b, c[a][i], curr ^ 1);
      if (k == 1) ans = 1;
    }
  } else {
    ans = 1;
    for (i = 0; i < v[b].size(); i++) {
      if (c[b][i] < last) continue;
      int k = func(a, v[b][i], c[b][i], curr ^ 1);
      if (k == 0) ans = 0;
    }
  }
  return ans;
}
int main() {
  memset(dp, -1, sizeof(dp));
  int n, m, i, j;
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) {
    int a, b;
    string s;
    scanf("%d%d", &a, &b);
    cin >> s;
    v[a].push_back(b);
    c[a].push_back(s[0] - 'a');
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++)
      if (func(i, j, 0, 0) == 1)
        printf("A");
      else
        printf("B");
    cout << endl;
  }
  return 0;
}
