#include <bits/stdc++.h>
using namespace std;
int dp[101][101][26][2];
vector<pair<int, char> > adj[101];
int get(int i, int j, char last, int st) {
  if (dp[i][j][last - 'a'][st] != -1) return dp[i][j][last - 'a'][st];
  if (st) {
    int k, ans = 0;
    for (k = 0; k < adj[i].size(); k++) {
      pair<int, char> x = adj[i][k];
      if (x.second >= last) ans = max(ans, get(x.first, j, x.second, !st));
    }
    return dp[i][j][last - 'a'][st] = ans;
  } else {
    int k, ans = 0;
    for (k = 0; k < adj[j].size(); k++) {
      pair<int, char> x = adj[j][k];
      if (x.second >= last) ans = max(ans, get(i, x.first, x.second, !st) ^ 1);
    }
    return dp[i][j][last - 'a'][st] = !ans;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  ;
  cin.tie(0);
  cout.tie(0);
  int n, m, i, j, x, y;
  char ch;
  cin >> n >> m;
  memset(dp, -1, sizeof(dp));
  for (i = 0; i < m; i++) {
    cin >> x >> y >> ch;
    adj[x].push_back({y, ch});
  }
  for (i = 1; i < n + 1; i++) {
    for (j = 1; j < n + 1; j++) {
      if (get(i, j, 'a', 1))
        cout << "A";
      else
        cout << "B";
    }
    cout << "\n";
  }
  return 0;
}
