#include <bits/stdc++.h>
using namespace std;
vector<pair<int, char> > gph[110];
int mv[110] = {0};
int vis[110] = {0};
int dp[110][110][26] = {0};
int gb = 0;
int ans(int a, int b, char c) {
  if (dp[a][b][c] != 0) {
    return dp[a][b][c];
  }
  int s1 = gph[a].size();
  int s2 = gph[b].size();
  for (int i = 0; i < s1; i++) {
    pair<int, char> u = gph[a][i];
    if (u.second < c) continue;
    int fg = 1;
    for (int j = 0; j < s2; j++) {
      pair<int, char> v = gph[b][j];
      if (u.second <= v.second) {
        int val = ans(u.first, v.first, v.second);
        if (val == 1) {
        } else {
          fg = 2;
          break;
        }
      }
    }
    if (fg == 1) dp[a][b][c] = 1;
  }
  if (!dp[a][b][c]) dp[a][b][c] = 2;
  return dp[a][b][c];
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    char c;
    cin >> u >> v >> c;
    gph[u].push_back(pair<int, char>(v, c - 'a'));
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 26; ++j) {
      dp[i][i][j] = 2;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      int a = ans(i, j, 0);
      if (a == 1) {
        cout << "A";
      } else
        cout << "B";
    }
    cout << endl;
  }
  return 0;
}
