#include #include #include int cmp_str (const void *a, const void *b) { return strcmp(*(char **)a, *(char **)b); } int main () { int n = 0; int l = 0; int q = 0; char s[1000][3001] = {}; int p = 0; int k = 0; char c = '\0'; char d = '\0'; char t[3001] = ""; int res = 0; char *sp[1000] = {}; res = scanf("%d", &n); res = scanf("%d", &l); res = scanf("%d", &q); for (int i = 0; i < n; i++) { res = scanf("%s", s[i]); sp[i] = s[i]; } qsort(sp, n, sizeof(char *), cmp_str); while (q > 0) { res = scanf("%d", &p); if (p == 1) { res = scanf("%d", &k); res = scanf("%c", &c); res = scanf("%c", &c); res = scanf("%c", &d); res = scanf("%c", &d); k--; for (int i = 0; i < n; i++) { if (sp[i][k] == c) { sp[i][k] = d; } } qsort(sp, n, sizeof(char *), cmp_str); } else { int ans[2][2] = { { -1, n }, { -1, n } }; res = scanf("%s", t); while (ans[0][1]-ans[0][0] > 1) { int nxt = (ans[0][0]+ans[0][1])/2; if (strcmp(sp[nxt], t) < 0) { ans[0][0] = nxt; } else { ans[0][1] = nxt; } } for (int i = 0; i < l; i++) { if (t[i] == '\0') { t[i] = 'z'; t[i+1] = '\0'; } } while (ans[1][1]-ans[1][0] > 1) { int nxt = (ans[1][0]+ans[1][1])/2; if (strcmp(sp[nxt], t) <= 0) { ans[1][0] = nxt; } else { ans[1][1] = nxt; } } printf("%d\n", ans[1][1]-ans[0][1]); } q--; } return 0; }