#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000001;
const long double EPS = 1e-9;
const int MOD = 1000000007;
const long long LLINF = 1000000000000000001;
const int maxn = 142;
vector<pair<int, int> > gr[maxn];
vector<int> gr2[maxn];
bool win[maxn][maxn][30];
int n, m;
int ord[maxn];
int pi;
bool seen[maxn];
void dfs1(int a) {
  seen[a] = true;
  for (auto i : gr[a])
    if (!seen[i.first]) dfs1(i.first);
  ord[pi++] = a;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int cc = 1; cc <= m; cc++) {
    int a, b;
    char c;
    cin >> a >> b >> c;
    gr[a].push_back(make_pair(b, int(c - 'a')));
    gr2[b].push_back(a);
  }
  pi = 1;
  for (int i = 1; i <= n; i++) seen[i] = false;
  for (int i = 1; i <= n; i++)
    if (!seen[i]) dfs1(i);
  int ee = 'z' - 'a' + 1;
  for (int c = ee - 1; c >= 0; c--)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= i; j++) {
        for (auto e : gr[ord[i]]) {
          if (e.second >= c && !win[ord[j]][e.first][e.second])
            win[ord[i]][ord[j]][c] = true;
        }
        for (auto e : gr[ord[j]]) {
          if (e.second >= c && !win[ord[i]][e.first][e.second])
            win[ord[j]][ord[i]][c] = true;
        }
      }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (win[i][j][0])
        cout << 'A';
      else
        cout << 'B';
    }
    cout << '\n';
  }
}
