#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;
const int P = 239017;
const long long BINF = 1e18 + 10;
const long double PI = acos(-1);
vector<int> arr;
int go[110][110][30], n;
bool used[110], dp[101][101][26][2];
void dfs(int v) {
  used[v] = true;
  for (int u = 1; u <= n; u++) {
    for (int c = 0; c < 26; c++) {
      if (go[v][u][c] && !used[u]) {
        dfs(u);
      }
    }
  }
  arr.push_back(v);
}
inline void source() {
  int m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    char cost;
    cin >> a >> b >> cost;
    go[a][b][cost - 'a'] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i]) {
      dfs(i);
    }
  }
  for (auto i : arr) {
    for (auto j : arr) {
      for (auto k : arr) {
        for (int c = 0; c < 26; c++) {
          if (go[i][k][c] && !dp[k][j][c][1]) {
            for (int c2 = c; c2 >= 0; c2--) {
              if (dp[i][j][c2][0]) {
                break;
              }
              dp[i][j][c2][0] = true;
            }
          }
          if (go[j][k][c] && !dp[i][k][c][0]) {
            for (int c2 = c; c2 >= 0; c2--) {
              if (dp[i][j][c2][1]) {
                break;
              }
              dp[i][j][c2][1] = true;
            }
          }
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cout << (dp[i][j][0][0] ? 'A' : 'B');
    }
    cout << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  source();
  return 0;
}
