#include <bits/stdc++.h>
using namespace std;
vector<int> ds;
vector<vector<pair<int, int> > > es;
vector<bool> bolo;
vector<vector<vector<int> > > dyn;
vector<int> pocet_hran;
vector<int> to_remove;
int n, m, sx, sy;
bool da_sa = true;
long long PRIME = 1e9 + 7;
long long fakt[1000000 + 7];
long long inv_a[1000000 + 7];
vector<vector<pair<int, char> > > G;
char ZAC = 'a' - 1;
void rec(int v1, int v2, char last_c) {
  int res = 1;
  for (auto vn : G[v1]) {
    if (vn.second >= last_c) {
      if (dyn[v2][vn.first][vn.second] == 0) rec(v2, vn.first, vn.second);
      res = min(dyn[v2][vn.first][vn.second], res);
      if (res == -1) break;
    }
  }
  dyn[v1][v2][last_c] = -res;
}
int main() {
  cin >> n >> m;
  G.resize(n);
  int a, b;
  char c;
  for (int i = 0; i < (m); i++) {
    cin >> a >> b >> c;
    a--;
    b--;
    c -= ZAC;
    G[a].push_back(make_pair(b, c));
  }
  dyn.resize(n, vector<vector<int> >(n, vector<int>('z' - 'a' + 2)));
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (n); j++) {
      for (int k = 0; k < (dyn[0][0].size()); k++) {
        if (dyn[i][j][k] == 0) {
          rec(i, j, k);
        }
      }
      if (dyn[i][j][0] == 1)
        cout << "A";
      else
        cout << "B";
    }
    cout << endl;
  }
}
