#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const long long inf = 1000000000000;
int D[111][111][33];
vector<pair<int, int> > V[111];
int n, m;
int F(int p, int q, int r) {
  if (D[p][q][r]) return D[p][q][r];
  int ret = 0;
  for (pair<int, int> t : V[p]) {
    if (t.second >= r) ret |= (F(q, t.first, t.second) - 1);
  }
  ret = 2 - ret;
  return D[p][q][r] = ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j, a, b, c;
  string st;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> st;
    V[a].push_back(pair<int, int>(b, st[0] - 'a'));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cout << char(F(i, j, 0) + 'A' - 1);
    }
    cout << '\n';
  }
  return 0;
}
