#include <bits/stdc++.h>
const int mod = 1000000007;
const int inf = 1000000009;
const long long int INF = 1000000000000000009;
using namespace std;
bool DP[101][101][27];
bool O[101][101][27];
vector<pair<int, int> > P[101];
bool dfs(int a, int b, int x) {
  if (O[a][b][x]) return DP[a][b][x];
  bool czy = false;
  for (int i = 0; i < P[a].size(); i++) {
    if (P[a][i].second >= x) {
      bool z;
      if (O[b][P[a][i].first][P[a][i].second])
        z = DP[b][P[a][i].first][P[a][i].second];
      else
        z = dfs(b, P[a][i].first, P[a][i].second);
      if (!z) {
        O[a][b][x] = true;
        return DP[a][b][x] = true;
      }
    }
  }
  O[a][b][x] = true;
  return DP[a][b][x] = false;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    char x;
    cin >> a >> b >> x;
    int c = (int)x - 96;
    P[a].push_back(make_pair(b, c));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dfs(i, j, 0);
      if (DP[i][j][0])
        cout << 'A';
      else
        cout << 'B';
    }
    cout << "\n";
  }
  return 0;
}
