#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include using namespace std; using namespace atcoder; #define rep(i,m,n,k) for (int i = (int)(m); i < (int)(n); i += (int)(k)) #define rrep(i,m,n,k) for (int i = (int)(m); i > (int)(n); i += (int)(k)) #define ll long long #define list(T,A,N) vector A(N);for(int i=0;i<(int)(N);i++){cin >> A[i];} template bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;} template bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;} // #define int long long constexpr int L = 26*27+1; constexpr int M = 26; array op( array x,array y){ array z; rep(i,0,L,1){ z[i] = x[i]+y[i]; } rep(i,0,M,1){ rep(j,0,M,1){ if(i!=j){ z[L-1] = (z[L-1] + x[i]*y[M*(i+1)+j] + x[M*(i+1)+i]*y[j]); } z[M*(i+1)+j] = z[M*(i+1)+j] + x[i]*y[j]; } } return z; } array e(){ array z; rep(i,0,L,1){ z[i] = 0; } return z; } array conv(char s){ array z; rep(i,0,L,1){ z[i] = 0; } z[s-'A'] = 1; return z; } int main(){ // ios::sync_with_stdio(false); // std::cin.tie(nullptr); int N; cin >> N; string S; cin >> S; int Q; cin >> Q; vector> I; for(auto s:S){ I.push_back(conv(s)); } segtree,op,e> T(I); int t,x,l,r; char c; rep(_,0,Q,1){ cin >> t; if(t==1){ cin >> x >> c; x -= 1; T.set(x,conv(c)); } else{ cin >> l >> r; l -= 1; cout << T.prod(l,r)[L-1] << "\n"; } } return 0; }