/**
 * @author pvasilyev
 * @since 19 Jun 2016
 */
object A365 extends App {

  def checkKGood(num: String, k: Int): Boolean = {
    for (i <- 0 to k) {
      if (!num.contains(i.toString)) {
        return false
      }
    }
    true
  }

  def solve() = {
    val Array(n, k): Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    var answer = 0
    for (i <- 0 until n) {
      val num = scala.io.StdIn.readLine()
      if (checkKGood(num, k)) {
        answer += 1
      }
    }

    println(answer)
  }

  solve()

}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.util.Random

object P365A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N, K = sc.nextInt
  sc.nextLine

  def solve(): Int = {
    val a0 = List.range(0, K + 1).map(_ + '0')
    List.fill(N)(sc.nextLine).count { s =>
      s.toList.distinct.sortWith(_ < _).take(K + 1) == a0
    }
  }

  out.println(solve)
  out.close
}

object A365 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    val Array(n, k) = readInts(2)
    var res = (1 to n).count{ _ =>
      val in = read
      in.toSet.count(_ <= k+'0') == k + 1
    }
    out.println(res)
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInt: Int = tokenizeLine.nextToken.toInt

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}

object Main {
  def main(args: Array[String]) {
    val Array(n, k) = readLine().split(" ").map(_.toInt)
    val a = (1 to n).map(_ => readLine())
    val digits = (Set() ++ (0 to k)).map('0' +).map(_.toChar)
    val count = a.foldLeft(0) { (acc, str) =>
      if ((digits &~ str.toSet) == Set()) acc + 1
      else acc
    }
    println(count)
  }
}

import java.util.Scanner
import scala.collection.mutable.HashSet

object GoodNumber extends App {
    val scan = new Scanner(System.in)
    val n = scan.nextInt
    val k = scan.nextInt

    def check(number: Int): Boolean = {
        var set = HashSet[Int]()
        var x = number
        do{
            if(x % 10 <= k) set = set + (x % 10)
            x = x / 10
        } while(x != 0)

        set == (0 to k).toSet
    }

    val ans = {
        for(i <- 0 until n) yield scan.nextInt
    }.toArray.filter(check).size

    println(ans)
}

import scala.util.Sorting
import scala.io.StdIn

object App {

  def main(args: Array[String]) {

    val Array(n, s) = StdIn.readLine().split(" ").map(_.toInt)
    val k = s.toString.head

    println(Range(0,n).count{ p =>
      StdIn.readLine().toCharArray.filter(_ <= k).toSet.size > (k - '0')
    })

  }

}

object Main {
    def main(args : Array[String]) {
        val (n, k) = readLine().split(" ") match {
            case Array(n, k) => (n.toInt, k.toInt)
        }

        var cnt = 0
        for(i <- 1 to n) {
            if(isKNumber(readLine(), k.toString.charAt(0))) {
                cnt += 1
            }
        }

        println(cnt)
    }

    def isKNumber(num : String, k : Character) =
        (num.toCharArray.toSet filter { _ <= k }).size == k.toString.toInt + 1
}

import scala.collection._

object A extends App {

  def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val t = tokenizeLine; Array.fill(n)(t.nextToken.toInt) }

  val Array(n, k) = readInts(2)
  val as = Array.fill(n)(readLine.map(_ - '0').filter(_ <= k))

  println(as.count(a => a.distinct.size == k + 1))
}

object Solution365A extends App {

  def solution() {
    val n = _int
    val k = _int
    val count = 1.to(n).map(_ => _string).count(s => {
      0.to(k).forall(d => s.contains("" + d))
    })
    println(count)
  }

  //////////////////////////////////////////////////
  import java.util.Scanner
  val SC: Scanner = new Scanner(System.in)
  def _line: String = SC.nextLine
  def _int: Int = SC.nextInt
  def _long: Long = SC.nextLong
  def _string: String = SC.next
  solution()
}

import scala.util.control.Breaks

/**
 * Created with IntelliJ IDEA.
 * User: teots
 * Date: 11/21/13
 * Time: 3:46 PM
 * To change this template use File | Settings | File Templates.
 */
object A {
  def main(args: Array[String]) {
    val line: String = readLine()
    val tokens: Array[String] = line.split(" ")
    val n = Integer.parseInt(tokens(0))
    val k = Integer.parseInt(tokens(1))

    var counter = 0

    val loop = new Breaks
    val loop2 = new Breaks

    for(i <- Range(1, n + 1 ))
    {
      val input : String = readLine()
      var found: Boolean = false

      loop.breakable{
        for (x <- Range(0, k + 1)) {
          found = false
          loop2.breakable {
            for(y <- input)
            {
              if(x == (y - 48))
              {
                found = true
                loop2.break
              }
            }
          }

          if(!found)
          {
             loop.break()
          }
        }

        counter += 1
      }
    }

    println(counter)
  }
}

import java.util.Scanner
import java.net.InetAddress
import java.security.MessageDigest

/**
 * Contest 213, Div 2, problem A
 *
 *
Let's call a number k-good if it contains all digits not
 * exceeding k (0, ..., k). You've got a number k and an array a
 * containing n numbers. Find out how many k-good numbers are in
 * a (count each number every time it occurs in array a).

 */
object Round213_Div2_Task1 {
  val inputScan = {
    val md = MessageDigest.getInstance("SHA-1")
    val userName = System.getProperty("user.name")
    val hostName = InetAddress.getLocalHost.getHostName

    val b = md.digest((userName + hostName).getBytes)
    var result = ""
    for (i ← 0 until b.length)
      result += Integer.toString((b(i) & 0xff) + 0x100, 16).substring(1)

    if (result == "51a302f8ba1abe181e33fe86c0ab4c7bedfb6c91") new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    else new Scanner(System.in)
  }

  def main(args: Array[String]) {
    val scan = inputScan

    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    for { ni ← 1 to n } {
      val arr = scan.nextLine.toCharArray.distinct
      if (arr.length >= (k + 1) && (0 to k).forall(p => arr.contains(p + '0')))
        c += 1
    }

    println(c)
  }
}

import java.util.Scanner
import java.net.InetAddress
import java.security.MessageDigest

/**
 * Contest 213, Div 2, problem A
 *
 *
Let's call a number k-good if it contains all digits not
 * exceeding k (0, ..., k). You've got a number k and an array a
 * containing n numbers. Find out how many k-good numbers are in
 * a (count each number every time it occurs in array a).

 */
object Round213_Div2_Task1 {
  val inputScan = {
    val md = MessageDigest.getInstance("SHA-1")
    val userName = System.getProperty("user.name")
    val hostName = InetAddress.getLocalHost.getHostName

    val b = md.digest((userName + hostName).getBytes)
    var result = ""
    for (i ← 0 until b.length)
      result += Integer.toString((b(i) & 0xff) + 0x100, 16).substring(1)

    if (result == "51a302f8ba1abe181e33fe86c0ab4c7bedfb6c91") new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    else new Scanner(System.in)
  }

  def main(args: Array[String]): Unit = {
    val scan = inputScan

    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    val digits = ('0' to ('0' + k).toChar).toArray
    for { ni ← 1 to n } {
      val arr = scan.nextLine.toCharArray.distinct
      if (arr.length >= (k + 1) && digits.forall(arr.contains(_)))
        c += 1
    }

    println(c)
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(" ").map(_.toInt)
  val ch = k.toString.head
  println(Range(0, n).count { _ =>
    val a = in.next().toSet
    Range(0, k + 1).forall(t => a.contains(t.toString.head))
  })
}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.util.Random

object P365A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N, K = sc.nextInt
  sc.nextLine

  def solve(): Int = {
    val a0 = List.range(0, K + 1).map(_ + '0')
    List.fill(N)(sc.nextLine).count { s =>
      s.toList.distinct.take(K + 1).sortWith(_ < _) == a0
    }
  }

  out.println(solve)
  out.close
}

object Main {
  def main(args: Array[String]) {
    val Array(n, k) = readLine().split(" ").map(_.toInt)
    val a = (1 to n).map(_ => readLine())
    val digits = (Set() ++ (0 to k)).map('0' +).map(_.toChar)
    val count = a.foldLeft(0) { (acc, str) =>
      if ((str.toSet &~ digits) == Set() && (digits &~ str.toSet) == Set()) acc + 1
      else acc
    }
    println(count)
  }
}

object Main {
  def main(args: Array[String]) {
    val Array(n, k) = readLine().split(" ").map(_.toInt)
    val a = (1 to n).map(_ => readLine())
    val digits =
      if (k != 0) (Set() ++ (0 to k)).map('0' +).map(_.toChar)
      else Set('0', '1')
    val count = a.foldLeft(0) { (acc, str) =>
      if ((str.toSet &~ digits) == Set() && (digits &~ str.toSet) == Set()) acc + 1
      else acc
    }
    println(count)
  }
}

import java.util.Scanner
import scala.collection.mutable.HashSet

object GoodNumber extends App {
    val scan = new Scanner(System.in)
    val n = scan.nextInt
    val k = scan.nextInt

    def check(number: Int): Boolean = {
        var set = HashSet[Int]()
        var x = number
        do{
            set = set + (x % 10)
            x = x / 10
        } while(x != 0)

        set == (0 to k).toSet
    }

    val ans = {
        for(i <- 0 until n) yield scan.nextInt
    }.toArray.filter(check).size

    println(ans)
}

import math._
import scala.util._
import java.util.Scanner

object Task1 {
  def main(args: Array[String]) {
    val scan = new Scanner(System.in)
    //val scan = new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    for { ni <- 1 to n } {
      val arr = scan.nextLine.toCharArray
      if (arr.length == k + 1 && arr.forall(p => p - '0' <= k))
        c += 1
    }

    println(c)
  }
}

//package com.myltsev.codeforces.round213

import java.util.Scanner
import java.net.InetAddress
import java.security.MessageDigest

object Task1 {
  val inputScan = {
    val md = MessageDigest.getInstance("SHA-1")
    val userName = System.getProperty("user.name")
    val hostName = InetAddress.getLocalHost.getHostName

    val b = md.digest((userName + hostName).getBytes)
    var result = ""
    for (i ← 0 until b.length)
      result += Integer.toString((b(i) & 0xff) + 0x100, 16).substring(1)

    if (result == "51a302f8ba1abe181e33fe86c0ab4c7bedfb6c91") new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    else new Scanner(System.in)
  }

  def main(args: Array[String]) {
    val scan = inputScan

    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    for { ni ← 1 to n } {
      val arr = scan.nextLine.toCharArray.distinct
      if (arr.length == (k + 1) && arr.forall(p ⇒ (p - '0') <= k))
        c += 1
    }

    println(c)
  }
}

import math._
import scala.util._
import java.util.Scanner

object Task1 {
  def main(args: Array[String]) {
    val scan = new Scanner(System.in)
    //val scan = new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    for { ni <- 1 to n } {
      val arr = scan.nextLine.toCharArray.distinct
      if (arr.length == (k + 1) && arr.forall(p => (p - '0') <= k))
        c += 1
    }

    println(c)
  }
}

import math._
import scala.util._
import java.util.Scanner

object Task1 {
  def main(args: Array[String]) {
    val scan = new Scanner(System.in)
    //val scan = new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    for { ni <- 1 to n } {
      val arr = scan.nextLine.toCharArray.distinct
      if (arr.length == k + 1 && arr.forall(p => p - '0' <= k))
        c += 1
    }

    println(c)
  }
}

import math._
import scala.util._
import java.util.Scanner

object Task1 {
  def main(args: Array[String]) {
    val scan = new Scanner(System.in)
    //val scan = new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    for { ni <- 1 to n } {
      if (scan.nextLine.toCharArray.distinct.length == k + 1)
        c += 1
    }

    println(c)
  }
}

//package com.myltsev.codeforces.round213

import java.util.Scanner
import java.net.InetAddress
//import java.security.MessageDigest

object Task1 {
  val inputScan = {
    //val md = MessageDigest.getInstance("SHA-1")
    val userName = System.getProperty("user.name")
    val hostName = InetAddress.getLocalHost.getHostName

    if (userName + hostName == "alexthe-PCU") new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    else new Scanner(System.in)

//    val b = md.digest((userName + hostName).getBytes)
//    var result = ""
//    for (i ← 0 until b.length)
//      result += Integer.toString((b(i) & 0xff) + 0x100, 16).substring(1)

//    if (result == "51a302f8ba1abe181e33fe86c0ab4c7bedfb6c91") new Scanner(new java.io.FileInputStream("tmp/0.txt"))
//    else new Scanner(System.in)
  }

  def main(args: Array[String]) {
    val scan = inputScan

    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    for { ni ← 1 to n } {
      val arr = scan.nextLine.toCharArray.distinct
      if (arr.length == (k + 1) && arr.forall(p ⇒ (p - '0') <= k))
        c += 1
    }

    println(c)
  }
}

// Read inputs from System.in, Write outputs to use print.
// Your class name has to be Solution

import math._
import scala.util._
import java.util.Scanner

object Task1 {
  def main(args: Array[String]) {
    val scan = new Scanner(System.in)
    //val scan = new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    for { ni <- 1 to n } {
      if (scan.nextLine.forall(x => x - '0' <= k))
        c += 1
    }

    println(c)
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(" ").map(_.toInt)
  val ch = k.toString.head
  println(Range(0, n).count(_ => in.next().forall(_ <= ch)))
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(" ").map(_.toInt)
  val ch = k.toString.head
  println(Range(0, n).count{_ =>
    val a = in.next().distinct
    a.length == (k + 1) && a.forall(_ <= ch)})
}

object A365 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    val Array(n, k) = readInts(2)
    var res = (1 to n).count{ _ =>
      val in = read.distinct.sorted
      if(in.length == k+1)
        in.zipWithIndex.forall{case (char, i) => char-'0' == i}
      else
        false
    }
    out.println(res)
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInt: Int = tokenizeLine.nextToken.toInt

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}

object A365 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    val Array(n, k) = readInts(2)
    var res = (1 to n).count{ _ =>
      val in = read.distinct.sorted
      in.zipWithIndex.forall{case (char, i) => char-'0' == i}
    }
    out.println(res)
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInt: Int = tokenizeLine.nextToken.toInt

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}

object A365 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    val Array(n, k) = readInts(2)
    var res = (1 to n).count{ _ =>
      val in = read.distinct.sorted
      in.take(k+1).zipWithIndex.forall{case (char, i) => char-'0' == i}
    }
    out.println(res)
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInt: Int = tokenizeLine.nextToken.toInt

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}

import scala.collection._

object A extends App {

  def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val t = tokenizeLine; Array.fill(n)(t.nextToken.toInt) }

  val Array(n, k) = readInts(2)
  val as = Array.fill(n)(readLine.toLong)

  def ok(x0: Long, k: Int): Boolean = {
    var x = x0
    var digits = new mutable.BitSet(10)
    var ok = true
    while (x > 0 && ok) {
      val d = (x % 10).toInt
      if (d > k) ok = false else digits += d
      x /= 10
    }
    ok && digits.size == k + 1
  }

  println(as.count(ok(_, k)))
}

import scala.collection._

object A extends App {

  def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val t = tokenizeLine; Array.fill(n)(t.nextToken.toInt) }

  val Array(n, k) = readInts(2)
  val as = Array.fill(n)(readLine.map(_ - '0'))

  println(as.count(a => a.distinct.size == k + 1))
}

import scala.collection._

object A extends App {

  def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val t = tokenizeLine; Array.fill(n)(t.nextToken.toInt) }

  val Array(n, k) = readInts(2)
  val as = Array.fill(n)(readLine.map(_ - '0'))

  println(as.count(a => a.max <= k && a.distinct.size == k + 1))
}

import scala.collection._

object A extends App {

  def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val t = tokenizeLine; Array.fill(n)(t.nextToken.toInt) }

  val Array(n, k) = readInts(2)
  val as = Array.fill(n)(readLine.toLong)

  def ok(x0: Long, k: Int): Boolean = {
    var x = x0
    var first = true
    var digits = new mutable.BitSet(10)
    var ok = true
    while ((x > 0 || first) && ok) {
      first = false
      val d = (x % 10).toInt
      if (d > k) ok = false else digits += d
      x /= 10
    }
    ok && digits.size == k + 1
  }

  println(as.count(ok(_, k)))
}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.util.Random

object P365A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N, K = sc.nextInt
  sc.nextLine

  def solve(): Int = {
    List.fill(N)(sc.nextLine).count { s =>
      s.toList.forall (_ < '1' + K)
    }
  }

  out.println(solve)
  out.close
}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.util.Random

object P365A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N, K = sc.nextInt
  sc.nextLine

  def solve(): Int = {
    val a0 = List.range(0, K + 1).map(_ + '0')
    List.fill(N)(sc.nextLine).count { s =>
      s.toList.distinct.sortWith(_ < _) == a0
    }
  }

  out.println(solve)
  out.close
}


object Solution extends App {
  val in = io.Source.stdin.getLines()
  val str = in.next()
  val (state, res) = str.foldLeft((0, List.empty[Char])) {
    case((0, acc), 'a') => (0, 'a' :: acc)
    case((0, acc), el) => (1, (el - 1).toChar :: acc)
    case((1, acc), 'a') => (2, 'a' :: acc)
    case((1, acc), el) => (1, (el - 1).toChar :: acc)
    case((2, acc), el) => (2, el :: acc)
  }
  if (state == 0)
    println(('z' :: res.tail).reverse.mkString)
  else
    println(res.reverse.mkString)

}

object A708 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    val in = read.toCharArray
    var idxa = in.indexOf('a')
    if(idxa != 0) {
      if(idxa == -1) idxa = in.length
      for(i <- 0 until idxa) {
        in(i) = (in(i)-1).toChar
      }
    } else {
      val idxs = in.zipWithIndex.filter(_._1 == 'a').map(_._2) ++ Array(in.length)
      var break = false
      for(i <- 1 until idxs.length if !break) {
        if(idxs(i-1)+1 < idxs(i)) {
          for(j <- idxs(i-1)+1 until idxs(i))
            in(j) = (in(j)-1).toChar
          break = true
        }
      }
      if(!break)
        in(in.length-1) = (26+in.last-1).toChar
    }
    println(in.mkString(""))
  }

  object IO {
    @inline def read: String = scala.io.StdIn.readLine

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine;
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine;
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine;
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}

import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._, collection.Searching._

object _709C extends CodeForcesApp {
  override def apply(io: IO) = {import io.{read, write, writeAll}
    val s = read[String].toArray
    val n = s.length

    val range = s.indexOf('a').nonNegative match {
      case None => s.indices
      case Some(0) => s.indexWhere(_ != 'a').nonNegative match {
        case Some(i) => i until s.indexOf('a', i).nonNegative.getOrElse(n)
        case _ => (n-1) until n
      }
      case Some(x) => 0 until x
    }

    def shift(c: Char): Char = if (c == 'a') 'z' else (c - 1).toChar

    range.foreach(i => s(i) = shift(s(i)))

    write(s.mkString)
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def in(set: collection.Set[A]): Boolean = set(a)
    def some: Option[A] = Some(a)
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = assuming(t.size == 1)(t.head)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {
    def key = p._1
    def value = p._2
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def lastKeyOption: Option[K] = m.lastOption.map(_.key)
    def firstKeyOption: Option[K] = m.headOption.map(_.key)
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
  }
  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {
    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)
    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)
    private def removeNode(kv: (K, V)): (K, V) = {
      m -= kv.key
      kv
    }
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)
    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
    def toEnglish = if(x) "YES" else "NO"
  }
  implicit class IntExtensions(val x: Int) extends AnyVal {
    import java.lang.{Integer => JInt}
    def withHighestOneBit: Int = JInt.highestOneBit(x)
    def withLowestOneBit: Int = JInt.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)
    def bitCount: Int = JInt.bitCount(x)
    def setLowestBits(n: Int): Int = x | (left(n) - 1)
    def clearLowestBits(n: Int): Int = x & left(n, ~0)
    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Int = x | left(i)
    def clearBit(i: Int): Int = x & ~left(i)
    def toggleBit(i: Int): Int = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)
    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    import java.lang.{Long => JLong}
    def withHighestOneBitSet: Long = JLong.highestOneBit(x)
    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)
    def bitCount: Int = JLong.bitCount(x)
    def setLowestBits(n: Int): Long = x | (left(n) - 1)
    def clearLowestBits(n: Int): Long = x & left(n, ~0L)
    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Long = x | left(i)
    def clearBit(i: Int): Long = x & ~left(i)
    def toggleBit(i: Int): Long = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf "Greg" whenNegative Int.MaxValue
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)
    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: => V): Dict[K, V] = using(_ => default)
    def using[V](f: K => V): Dict[K, V] = new mutable.HashMap[K, V]() {
      override def apply(key: K) = getOrElseUpdate(key, f(key))
    }
  }
  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]
  def memoize[A, B](f: A => B): A ==> B = map[A] using f
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {
    val (xs, ys) = points.unzip
    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)
  }
  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {
    val shape = new java.awt.geom.GeneralPath()
    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}
    points.tail foreach {case (x, y) => shape.lineTo(x, y)}
    shape.closePath()
    shape
  }
  def until(until: Int): Range = 0 until until
  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}
  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  type ==>[A, B] = collection.Map[A, B]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

class IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {
  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))
  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered
  val printer = new PrintWriter(out, true)

  @inline private[this] def tokenizer() = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    when(tokenizers.nonEmpty)(tokenizers.head)
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(read).to[C]

  def readTill(delim: String): String = tokenizer().get.nextToken(delim)
  def readTillEndOfLine(): String = readTill("\n\r")

  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty

  def write(obj: Any, more: Any*): this.type = {
    printer.print(obj)
    more foreach {i =>
      printer.print(' ')
      printer.print(i)
    }
    this
  }
  def writeAll(obj: Traversable[Any], separator: String = "\n"): this.type = write(obj mkString separator)

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }
  object Read {
    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val int                                          : Read[Int]          = string.map(_.toInt)
    implicit val long                                         : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                       : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                      : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  def shift(c: Char) = if (c == 'a') 'z' else (c - 1).toChar

  val s = readLine
  val s2 = s.map(shift)
  val n = s.length

  Console.setOut(new java.io.BufferedOutputStream(Console.out))

  val firstNonA = s.indexWhere(_ != 'a')

  val res = if (firstNonA == -1) {
    if (n == 1) s2
    else s.take(n - 1) + s2.last
  } else {
    val subsequentA = s.indexWhere(_ == 'a', firstNonA)
    if (subsequentA == -1) s.take(firstNonA) + s2.drop(firstNonA)
    else {
      s.take(firstNonA) + s2.slice(firstNonA, subsequentA) + s.drop(subsequentA)
    }
  }

  println(res)

  Console.flush
}

object A708 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    val in = read.toCharArray
    var idxa = in.indexOf('a')
    if(idxa != 0) {
      if(idxa == -1) idxa = in.length
      for(i <- 0 until idxa) {
        in(i) = (in(i)-1).toChar
      }
    } else {
      val idxs = in.zipWithIndex.filter(_._1 == 'a').map(_._2)
      var break = false
      for(i <- 1 until idxs.length if !break) {
        if(idxs(i-1)+1 < idxs(i)) {
          for(j <- idxs(i-1)+1 until idxs(i))
            in(j) = (in(j)-1).toChar
          break = true
        }
      }
    }
    println(in.mkString(""))
  }

  object IO {
    @inline def read: String = scala.io.StdIn.readLine

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine;
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine;
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine;
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}


object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val A = na(N)
    val topo = Array.fill[ArrayBuffer[Int]](N)(ArrayBuffer())
    val win = Array.ofDim[Char](N) // numberベース
    rep(N) { i =>
      val s = i % A(i)
      var j = s
      while (j < N) {
        if (A(j) > A(i)) {
          topo(A(i) - 1) += A(j) - 1
        }
        j += A(i)
      }
    }

    rep_r(N) { i =>
      val bob = topo(i) forall (j => win(j) == 'A')
      win(i) = if (bob) 'B' else 'A'
    }

    out.println(A map (i => win(i - 1)))
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val A = na(N)

    val win = Array.ofDim[Char](N)
    val looking = Array.fill[ArrayBuffer[Int]](N)(ArrayBuffer())
    val q = mutable.Queue[Int]()
    var cnt = 0

    rep(N) { i =>
      val s = i % A(i)
      var j = s
      var moves = 0
      while (j < N) {
        if (A(j) > A(i)) {
          looking(j) += i
          moves += 1
        }
        j += A(i)
      }

      if (moves == 0) {
        win(i) = 'B'
        cnt += 1
        q += i
      }
    }

    def test(i: Int) {
      val s = i % A(i)
      var j = s
      var allWin = true
      while (j < N) {
        if (A(j) > A(i)) {
          if (win(j) == 'B') {
            win(i) = 'A'
            cnt += 1
            q += i
            return
          }
          allWin &= win(j) == 'A'
        }
        j += A(i)
      }

      if (allWin) {
        win(i) = 'B'
        cnt += 1
        q += i
      }
    }

    while (cnt < N) {
      val i = q.dequeue()
      looking(i) foreach { j =>
        if (win(j) == 0) test(j)
      }
    }

    out.println(win.mkString)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}

object C extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(n) = readInts(1)
  val as = readInts(n)
  val bs = Array.fill(n){ ' ' }

  Console.setOut(new java.io.BufferedOutputStream(Console.out))

  def check(i: Int): Boolean = {
    if (bs(i) != ' ') bs(i) == 'A'
    else {
      val a = as(i)
      var j = i - a
      var canWin = false
      while (j >= 0 && !canWin) {
        if (as(j) > a && !check(j)) canWin = true
        j -= a
      }
      j = i + a
      while (j < n && !canWin) {
        if (as(j) > a && !check(j)) canWin = true
        j += a
      }
      bs(i) = if (canWin) 'A' else 'B'
      canWin
    }
  }

  var i = 0
  while (i < n) {
    if (bs(i) == ' ') check(i)
    i += 1
  }

  println(new String(bs))

  Console.flush
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val A = na(N)

    val win = Array.ofDim[Char](N)
    val looking = Array.fill[ArrayBuffer[Int]](N)(ArrayBuffer())
    val q = mutable.Queue[Int]()
    var cnt = 0

    rep(N) { i =>
      val s = i % A(i)
      var j = s
      while (j < N) {
        looking(j) += i
        j += A(i)
      }

      if (s == i && s + A(i) >= N) {
        win(i) = 'B'
        cnt += 1
        q += i
      }
    }

    def test(i: Int) {
      val s = i % A(i)
      var j = s
      var allWin = true
      while (j < N) {
        if (j != i) {
          if (win(j) == 'B') {
            win(i) = 'A'
            cnt += 1
            q += i
            return
          }
          allWin &= win(j) == 'A'
        }
        j += A(i)
      }

      if (allWin) {
        win(i) = 'B'
        cnt += 1
        q += i
      } else false
    }

    while (cnt < N) {
      val i = q.dequeue()
      looking(i) foreach { j =>
        if (win(j) == 0) test(j)
      }
    }

    out.println(win.mkString)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}


object A extends App {
  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val pn = readLine().split(" ").map(_.toInt)

    val ans = (0 until n - 2).collectFirst {
      case i if pn(i) < pn(i + 1) && pn(i + 2) < pn(i + 1) => (i + 1, i + 2, i + 3)
    }

    ans match {
      case Some((i, j, k)) =>
        println("YES")
        println(s"$i $j $k")
      case _ =>
        println("NO")
    }
  }
}

object A {
  import InOut._
  def main(args: Array[String]): Unit = {

    for (_ <- 1 to nextInt) {
      val n = nextInt
      val ps = nextInts(n)

      var i = 2
      var res = -1
      while (i < n) {
        if (ps(i - 1) > ps(i - 2) && ps(i) < ps(i - 1)) {
          res = i
        }
        i += 1
      }

      if (res == -1) {
        out.println("NO")
      } else {
        out.println("YES")
        out.println(s"${res - 1} ${res} ${res + 1}")
      }

      out.flush()
    }
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
  }
}

object A extends App {
  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val pn = readLine().split(" ").map(_.toInt)

    val ans = (0 until n - 2).collectFirst {
      case i if pn(i) < pn(i + 1) && pn(i + 2) < pn(i + 1) => (i + 1, i + 2, i + 3)
    }

    ans match {
      case Some((i, j, k)) => println(s"YES\n$i $j $k")
      case _               => println("NO")
    }
  }
}

object A extends App {
  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val pn = readLine().split(" ").map(_.toInt)

    val ans = pn.zipWithIndex.sliding(3, 1).collectFirst {
      case Array((pi, i), (pj, j), (pk, k)) if pi < pj && pk < pj => (i + 1, j + 1, k + 1)
    }

    ans match {
      case Some((i, j, k)) =>
        println("YES")
        println(s"$i $j $k")
      case _ =>
        println("NO")
    }
  }
}

import scala.io.StdIn._

object A extends App {

  def solve(A: Array[Int]): Option[Array[Int]] = {
    var a = 0
    var c = A.length - 1
    var b = 1

    while (a < b && b < c) {
      while (b < c) {
        if (A(a) < A(b) && A(b) > A(c)) return Some(Array(a, b, c))
        b += 1
      }

      if (A(a) < A(c)) c -= 1 else a += 1
      b = a + 1
    }

    None
  }

  val t = readInt()
  1 to t foreach { _ =>
    readInt()
    val A = readLine().split(" ").map(_.toInt)
    solve(A) match {
      case Some(xs) =>
        println("YES")
        println((xs(0) + 1) + " " + (xs(1) + 1) + " " + (xs(2) + 1))
      case None =>
        println("NO")
    }

  }

}

object ProblemA extends App {
  import java.io.{BufferedReader, InputStreamReader, PrintWriter}
  import java.util.StringTokenizer
  val in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)))
  val out = new PrintWriter(System.out)

  class FastScanner(val in: BufferedReader) {
    var st: StringTokenizer = _;

    def nextToken(): String = {
      while (st == null || !st.hasMoreTokens) {
        st = new StringTokenizer(in.readLine);
      }
      return st.nextToken();
    }

    def nextInt(): Integer = {
      Integer.parseInt(nextToken());
    }

    def nextLong(): Long = {
      nextToken().toLong;
    }

    def nextDouble(): Double = {
      nextToken().toDouble;
    }
  }

  val t = in.nextInt()
  for (_ <- 1 to t) {
    val n = in.nextInt()
    val minLeft = new Array[Int](n)
    val minRight = new Array[Int](n)
    val a = new Array[Int](n)

    for (i <- 0 until n) {
      a(i) = in.nextInt()
      if (i > 0) {
        minLeft(i) = math.min(a(i), minLeft(i - 1))
      } else {
        minLeft(i) = a(i)
      }
    }

    for (i <- (0 until n).reverse) {
      if (i < a.length - 1) {
        minRight(i) = math.min(a(i), minRight(i + 1))
      } else {
        minRight(i) = a(i)
      }
    }

    var ans = -1

    for (i <- 1 until n - 1) {
      if (a(i) > minLeft(i - 1) && a(i) > minRight(i + 1)) {
        ans = i
      }
    }

    if (ans == -1) {
      println("NO")
    } else {
      println("YES")
      println(s"${a.indexOf(minLeft(ans - 1)) + 1} ${ans + 1} ${a.indexOf(minRight(ans + 1)) + 1}")
    }
  }
}

object ProblemA extends App {
  import java.io.{BufferedReader, InputStreamReader, PrintWriter}
  import java.util.StringTokenizer
  val in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)))
  val out = new PrintWriter(System.out)

  class FastScanner(val in: BufferedReader) {
    var st: StringTokenizer = _;

    def nextToken(): String = {
      while (st == null || !st.hasMoreTokens) {
        st = new StringTokenizer(in.readLine);
      }
      return st.nextToken();
    }

    def nextInt(): Integer = {
      Integer.parseInt(nextToken());
    }

    def nextLong(): Long = {
      nextToken().toLong;
    }

    def nextDouble(): Double = {
      nextToken().toDouble;
    }
  }

  val t = in.nextInt()
  for (_ <- 1 to t) {
    val n = in.nextInt()
    val minLeft = new Array[Int](n)
    val minRight = new Array[Int](n)
    val a = new Array[Int](n)

    for (i <- 0 until n) {
      a(i) = in.nextInt()
      if (i > 0) {
        minLeft(i) = math.min(a(i), minLeft(i - 1))
      } else {
        minLeft(i) = a(i)
      }

      if (i < a.length - 1) {
        minRight(i) = math.min(a(i), minRight(i + 1))
      } else {
        minRight(i) = a(i)
      }
    }

    var ans = -1

    for (i <- 1 until n - 1) {
      if (a(i) > minLeft(i - 1) && a(i) > minRight(i + 1)) {
        ans = i
      }
    }

    if (ans == -1) {
      println("NO")
    } else {
      println("YES")
      println(s"${a.indexOf(minLeft(ans - 1))} $ans ${a.indexOf(minRight(ans + 1))}")
    }
  }
}

object ProblemA extends App {
  import java.io.{BufferedReader, InputStreamReader, PrintWriter}
  import java.util.StringTokenizer
  val in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)))
  val out = new PrintWriter(System.out)

  class FastScanner(val in: BufferedReader) {
    var st: StringTokenizer = _;

    def nextToken(): String = {
      while (st == null || !st.hasMoreTokens) {
        st = new StringTokenizer(in.readLine);
      }
      return st.nextToken();
    }

    def nextInt(): Integer = {
      Integer.parseInt(nextToken());
    }

    def nextLong(): Long = {
      nextToken().toLong;
    }

    def nextDouble(): Double = {
      nextToken().toDouble;
    }
  }

  val t = in.nextInt()
  for (_ <- 1 to t) {
    val n = in.nextInt()
    val minLeft = new Array[Int](n)
    val minRight = new Array[Int](n)
    val a = new Array[Int](n)

    for (i <- 0 until n) {
      a(i) = in.nextInt()
      if (i > 0) {
        minLeft(i) = math.min(a(i), minLeft(i - 1))
      } else {
        minLeft(i) = a(i)
      }

      if (i < a.length - 1) {
        minRight(i) = math.min(a(i), minRight(i + 1))
      } else {
        minRight(i) = a(i)
      }
    }

    var ans = -1

    for (i <- 1 until n - 1) {
      if (a(i) > minLeft(i - 1) && a(i) > minRight(i + 1)) {
        ans = i
      }
    }

    if (ans == -1) {
      println("NO")
    } else {
      println("YES")
      println(s"${a.indexOf(minLeft(ans - 1)) + 1} ${ans + 1} ${a.indexOf(minRight(ans + 1)) + 1}")
    }
  }
}


object B extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(n) = readInts(1)
  val as = readInts(n).sorted
  var wins = "Agasa"

  var i = n - 1
  while (i >= 0) {
    if (i == 0 || as(i) > as(i - 1)) {
      if ((n - i) % 2 == 1) wins = "Conan"
    }
    i -= 1
  }

  println(wins)
}

object CardGame2 extends App {
  val n = scala.io.StdIn.readLine().toLong
  val original = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val oddNumberOfCards = 1
  val evenNumberOfCards = 2

  val simplified = original.groupBy(x => x)
    .map { case (card, cardDuplicates) =>
      val oddOrEven = if (cardDuplicates.length % 2 == 0) evenNumberOfCards else oddNumberOfCards
      card -> oddOrEven
    }
    .toSeq.sortBy { case (card, _) => card }.reverse //desc sorting
    .map { case (_, evenOrOdd) => evenOrOdd }
    .distinct

  val solution = simplified.toList match {
    case `evenNumberOfCards` :: Nil => "Agasa"
    case _ => "Conan"
  }

  println(solution)

}

object B2 extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }

  val Array(n) = readInts(1)
  val check = readInts(n).groupBy(identity).valuesIterator.exists(_.length % 2 == 1)
  println(if (check) "Conan" else "Agasa")
}

object CardGame2 extends App {
  val n = scala.io.StdIn.readLine().toLong
  val original = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val oddNumberOfCards = 1
  val evenNumberOfCards = 2

  val simplified = original.groupBy(x => x)
    .map { case (card, cardDuplicates) =>
      val oddOrEven = if (cardDuplicates.length % 2 == 0) evenNumberOfCards else oddNumberOfCards
      card -> oddOrEven
    }
    .toSeq.sortBy { case (card, _) => card }.reverse //desc sorting
    .map { case (_, evenOrOdd) => evenOrOdd }

  val solution = simplified.toList match {
    case `evenNumberOfCards` :: Nil => "Agasa"
    case _ => "Conan"
  }

  println(solution)

}