using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			string s = cin.Next();
			int q = cin.Int();

			var segs = new SegmentTree<int>(n, 0, (x, y) => x | y);
			for (int i = 0; i < n; i++) {
				var c = s[i] - 'a';
				segs.Update(i, 1 << c);
			}

			var sb = new StringBuilder();
			for (int i = 0; i < q; i++) {
				int qq = cin.Int();
				if (qq == 1) {
					int ii = cin.Int() - 1;
					int c = cin.Next()[0] - 'a';
					segs.Update(ii, 1 << c);
				} else {
					int l = cin.Int() - 1;
					int r = cin.Int();
					int cnt = 0;
					int cs = segs.Query(l, r);
					for (int j = 0; j < 26; j++) {
						if ((cs & (1 << j)) != 0) {
							cnt++;
						}
					}

					sb.AppendLine(cnt.ToString());
				}
			}

			Console.WriteLine(sb.ToString());
		}
	}

	public class SegmentTree<T>
	{
		private readonly int n_;
		private readonly T unit_;
		private readonly T[] tree_;
		private readonly Func<T, T, T> merge_;

		public int Count { get; }
		public T Top => tree_[1];

		public SegmentTree(int count, T unit, Func<T, T, T> merge)
		{
			merge_ = merge;
			unit_ = unit;

			Count = count;
			n_ = 1;
			while (n_ < count) {
				n_ <<= 1;
			}

			tree_ = new T[n_ << 1];
			for (int i = 0; i < tree_.Length; i++) {
				tree_[i] = unit;
			}
		}

		public SegmentTree(T[] src, T max, Func<T, T, T> merge)
			: this(src.Length, max, merge)
		{
			for (int i = 0; i < n_; ++i) {
				tree_[i + n_] = src[i];
			}

			for (int i = n_ - 1; i > 0; --i) {
				tree_[i] = merge_(tree_[i << 1], tree_[(i << 1) + 1]);
			}
		}

		public T this[int index]
		{
			get { return tree_[index + n_]; }
			set { Update(index, value); }
		}

		public void Update(int index, T val)
		{
			if (index >= Count) {
				return;
			}

			index += n_;
			tree_[index] = val;
			index >>= 1;
			while (index != 0) {
				tree_[index] = merge_(tree_[index << 1], tree_[(index << 1) + 1]);
				index >>= 1;
			}
		}

		public T Query(int left, int right)
		{
			if (left > right || right < 0 || left >= Count) {
				return unit_;
			}

			int l = left + n_;
			int r = right + n_;
			T valL = unit_;
			T valR = unit_;
			while (l < r) {
				if ((l & 1) != 0) {
					valL = merge_(valL, tree_[l]);
					++l;
				}
				if ((r & 1) != 0) {
					--r;
					valR = merge_(tree_[r], valR);
				}

				l >>= 1;
				r >>= 1;
			}

			return merge_(valL, valR);
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private readonly Func<string> reader_;
		private string[] buf_;
		private int index_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 21596