#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define vi vector<int>

const int N = 1e5 + 5;

int n,q,v[N],root, nxt[N];

vector<int> b[400];

std::map<int, vi> save;

void runNxt()
{
	for (int i = 0; i < n; ++i)
	{
		save[v[i]].push_back(i);
	}
	for (int i = 0; i < n; ++i)
	{
		int idx = *upper_bound(all(save[v[i]]), i);
		nxt[i] = idx?idx:n + 1;
	}
}

int main(int argc, char const *argv[])
{

	string s; cin>>s;

	n = s.size();

	root=sqrt(n);
	
	int ct = (n + root - 1) / root;
	
	for(int i=0; i<n; ++i)
		v[i] = s[i] - 'a';
	
	runNxt();
	
	for(int i=0; i<n; ++i)
		b[i/root].push_back(nxt[i]);
	
	for(int i=0; i<ct; ++i)
		sort(b[i].begin(), b[i].end());
 	
 	int q; scanf("%d", &q);

	int T;

	for(int i, l, r; i < q; ++i)
	{
		scanf("%d", &T);

		if(T==2)
		{
			scanf("%d%d",&l,&r);
			
			--l;--r;

			int ans=0;

			for(int j=l; j<=r; ++j)
			{
				if(j%root==0 && j+root-1<=r)
				{
					ans+= upper_bound(b[j/root].begin(), b[j/root].end(), r) - b[j/root].begin();
					
					j+=root-1;
				}

				else if(nxt[j] > r)
				{
					++ans;
				}
			}

			printf("%d\n", ans);
		}
		else
		{
			char c;

			scanf("%d %c",&l,&c);
			
			--l;
			
			v[l] = c - 'a';

			int bucket = l / root;
			
			b[bucket].clear();
			
			for(int j=bucket*root; j<n && j<(bucket + 1)*root; ++j)
				b[bucket].push_back(*upper_bound(all(save[v[j]]), nxt[j]));
			
			sort(b[bucket].begin(), b[bucket].end());
		}
	}
	
}	