#include <bits/stdc++.h>
using namespace std;
const int DIM = 105;
bool dp[DIM][DIM][26], oki[DIM][DIM][26];
int rnk[DIM];
vector<pair<int, int>> edg[DIM];
int dfs(int x, int y, int k) {
  if (oki[x][y][k]) return dp[x][y][k];
  for (pair<int, int> it : edg[x]) {
    int z = it.first, c = it.second;
    if (c >= k and !dfs(y, z, c)) dp[x][y][k] = true;
  }
  oki[x][y][k] = true;
  return dp[x][y][k];
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int x, y;
    char ch;
    cin >> x >> y >> ch;
    edg[x].push_back(make_pair(y, ch - 'a'));
    ++rnk[y];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      bool as = dfs(i, j, 0);
      if (as == true)
        cout << 'A';
      else
        cout << 'B';
    }
    cout << "\n";
  }
  return 0;
}
