import sequtils

const ns = toSeq(0..32).mapIt($it & "\n")

var ip: string

var op = newString(100000)

var ii, io = 0

proc read: int {.inline.} =

  result = 0

  while ip[ii] >= '0':

    result = result * 10 + (ip[ii].ord - '0'.ord)

    ii += 1

proc print(i: int) {.inline.} =

  op[io] = ns[i][0]; io += 1

  op[io] = ns[i][1]; io += 1

  if ns[i].len > 2: op[io] = ns[i][2]; io += 1

import math

var N, n: int

var tr: seq[int]

proc build {.inline.} =

  N = read(); ii += 1;

  n = N.nextPowerOfTwo

  tr = newSeq[int](2*n)

  for i in countup(n, n+N-1):

    tr[i] = 1 shl (ip[ii].ord - 'a'.ord); ii += 1

  for i in countdown(n-1, 1):

    tr[i] = tr[i shl 1] or tr[i shl 1 or 1]

  ii += 1

proc query {.inline.} =

  if ip[ii] == '1':

    ii += 2

    var id = read() + n - 1; ii += 1

    let od = ip[ii].ord - 'a'.ord; ii += 2

    tr[id] = 1 shl od

    while (id = id shr 1; id > 0):

      tr[id] = tr[id shl 1] or tr[id shl 1 or 1]

  else:

    ii += 2

    var l = read() + n - 1; ii += 1

    var r = read() + n; ii += 1

    var res = 0

    while l < r:

      if bool(l and 1): res = res or tr[l]; l += 1

      if bool(r and 1): r -= 1; res = res or tr[r]

      l = l shr 1; r = r shr 1

    print(countBits32(res.int32))

block main:

  ip = stdin.readAll

  build()

  let q = read(); ii += 1

  for _ in 1..q: query()

  stdout.write op[0..io-1]

