#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 20, K = 11;
int n, m, k, idx[K], cnt[K][K];
string s;
set<pair<pair<int, int>, int>> e;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m >> k;
  cin >> s;
  int st = 0;
  for (int i = 1; i < n; i++) {
    cnt[s[i - 1] - 'a'][s[i] - 'a']++;
    if (s[i] != s[i - 1]) {
      e.insert({{st, i}, s[st] - 'a'});
      st = i;
    }
  }
  e.insert({{st, n}, s[st] - 'a'});
  cout << endl;
  while (m--) {
    int type, l, r, c, ans = 1;
    string s;
    char ch;
    cin >> type;
    if (type & 1) {
      cin >> l >> r >> ch;
      c = ch - 'a';
      l--;
      vector<pair<pair<int, int>, int>> vec;
      while (e.size() && (e.begin()->first.first) <= r) {
        auto it = e.lower_bound({{r + 1, 0}, 0});
        it--;
        if (it->first.second < l) break;
        vec.push_back(*it);
        e.erase(it);
      }
      reverse(vec.begin(), vec.end());
      for (int i = 1; i < vec.size(); i++)
        cnt[vec[i - 1].second][vec[i].second]--;
      cnt[c][c] += r - l - 1;
      if (vec.front().first.first < l) cnt[vec.front().second][c]++;
      if (vec.back().first.second > r) cnt[c][vec.back().second]++;
      for (auto i : vec) {
        cnt[i.second][i.second] -= min(i.first.second, r) -
                                   max(i.first.first, l) - 1 +
                                   (i.first.first < l) + (r < i.first.second);
        if (i.first.first < l && i.second != c)
          e.insert({{i.first.first, l}, i.second});
        if (i.first.second > r && i.second != c)
          e.insert({{r, i.first.second}, i.second});
      }
      if (vec.front().second == c) l = vec.front().first.first;
      if (vec.back().second == c) r = vec.back().first.second;
      e.insert({{l, r}, c});
    } else {
      cin >> s;
      for (int i = 0; i < k; i++) idx[s[i] - 'a'] = i;
      for (int i = 0; i < k; i++)
        for (int j = 0; j < k; j++)
          if (idx[i] >= idx[j]) ans += cnt[i][j];
      cout << ans << "\n";
    }
  }
  return 0;
}
