#include <bits/stdc++.h>
using namespace std;
const long long lt = 100005;
long long mod = 1000000007;
vector<pair<long long, long long> > ad[104];
long long dp[105][105][27];
void calc(long long u, long long v, long long c) {
  if (dp[u][v][c] != -1) return;
  long long i, j;
  for (i = 0; i < (long long)(ad[u]).size(); i++) {
    long long flag = 0;
    pair<long long, long long> x1 = ad[u][i];
    if (x1.second < c) continue;
    for (j = 0; j < (long long)(ad[v]).size(); j++) {
      pair<long long, long long> x2 = ad[v][j];
      if (x2.second < x1.second) continue;
      calc(x1.first, x2.first, x2.second);
      if (dp[x1.first][x2.first][x2.second] == 0) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      dp[u][v][c] = 1;
      break;
    }
  }
  if (dp[u][v][c] == -1) dp[u][v][c] = 0;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long i, j, k;
  for (i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    char x;
    cin >> x;
    ad[a].push_back(make_pair(b, (long long)x - (long long)'a'));
  }
  for (i = 0; i <= 100; i++)
    for (j = 0; j <= 100; j++)
      for (k = 0; k <= 26; k++) dp[i][j][k] = -1;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) calc(i, j, 0);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      if (dp[i][j][0] == 0)
        cout << "B";
      else
        cout << "A";
    }
    cout << endl;
  }
  return 0;
}
