#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
const int N = 100, E = 26;
vector<int> adj[N][E];
int game[N][N][E];
int gaming(int v, int u, int i) {
  int &res = game[v][u][i];
  if (res == -1) {
    int win = 0;
    for (int j = i; j < E && win == 0; j++) {
      for (int k : adj[v][j]) {
        if (gaming(u, k, j) == 0) {
          win = 1;
          break;
        }
      }
    }
    res = win;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  memset(game, -1, sizeof game);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (int)(m); ++i) {
    int u, v;
    char e;
    cin >> u >> v >> e;
    u--;
    v--;
    adj[u][e - 'a'].push_back(v);
  }
  for (int u = 0; u < (int)(n); ++u) {
    for (int v = 0; v < (int)(n); ++v) {
      cout << ((gaming(u, v, 0) > 0) ? 'A' : 'B');
    }
    cout << endl;
  }
  return 0;
}
