import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}
import scala.collection.mutable.TreeSet

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val S = "0" + in.next()
  val Q = in.next().toInt


  //
  val dp = Array.fill[TreeSet[Int]](26)(TreeSet.empty)
  val s = new Array[Int](N+1)
  for (i <- 1 to N) {
    val now = S(i).toInt - 97
    dp(now) += i
    s(i) = now
  }

  for (_ <- 1 to Q) {
    val com = in.next().toInt
    if (com == 1) {
      val i = in.next().toInt
      val c = in.next()(0)

      val del = s(i)
      val now = c.toInt - 97
      s(i) = now

      dp(del) -= i
      dp(now) += i
    }
    else {
      val l, r = in.next().toInt
      var ans = 0
      for (i <- 0 until 26) {
        dp(i).minAfter(l).foreach { k =>
          if (k <= r)
            ans += 1
        }
      }
      pw.println(ans)
    }
  }

  pw.flush()
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
