#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<pair<int, char>>> adj_list;
int memo[270000][2];
int solve(int state, int turn) {
  if (memo[state][turn] == -1) {
    vector<int> player(2);
    player[0] = state % 100;
    player[1] = state / 100 % 100;
    char degree = 'a' + state / 10000;
    for (auto next : adj_list[player[turn]])
      if (next.second >= degree) {
        int next_state;
        if (turn == 0)
          next_state =
              (next.second - 'a') * 10000 + player[1] * 100 + next.first;
        else
          next_state =
              (next.second - 'a') * 10000 + next.first * 100 + player[0];
        if (turn == solve(next_state, !turn)) {
          memo[state][turn] = turn;
          return memo[state][turn];
        }
      }
    memo[state][turn] = !turn;
  }
  return memo[state][turn];
}
int main(void) {
  scanf("%d %d", &n, &m);
  adj_list.assign(n, vector<pair<int, char>>());
  int u, v;
  char ch;
  for (int i = 0; i < m; i++) {
    scanf("%d %d %c", &u, &v, &ch);
    adj_list[u - 1].push_back(pair<int, char>(v - 1, ch));
  }
  memset(memo, -1, sizeof(memo));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (solve(j * 100 + i, 0) == 0)
        printf("A");
      else
        printf("B");
    }
    printf("\n");
  }
  return 0;
}
