#!/bin/python3 import sys from itertools import combinations, permutations ''' abccbab bab abccba bccb cc ''' def palindrome_gen_(aa): def match(bb): if not bb: return False for i in range(len(bb) // 2): if aa[bb[i]] != aa[bb[-i - 1]]: return False return True stack = [([], 0)] while stack: base, index = stack.pop() print('base=%s' % base, file = sys.stderr) if match(base): yield base for i in range(index, len(aa)): stack.append((base + [i], i + 1)) def palindrome_gen(aa): def match(p): if not p: return False for i in range(len(p) // 2): if p[i] != p[len(p) - i - 1]: return False return True for i in range(1, len(aa) + 1): for c in combinations(aa, i): for p in permutations(c): if match(p): yield p break def rearrange(aa, i, j, t): #print('rearrange: %s %d' % (aa[i: j], t), file = sys.stderr) for index in range(i, j): c = aa[index] aa[index] = chr(ord('a') + (ord(c) - ord('a') + t) % (ord('z') - ord('a') + 1)) #print('rearranged: %s' % (aa[i: j]), file = sys.stderr) def count(aa, i, j, modulo): print('count: %s' % (aa[i: j],), file = sys.stderr) cnt = 0 for p in palindrome_gen(aa[i: j]): cnt += 1 #print('p=%s' % (p,), file = sys.stderr) return cnt % modulo def test(): s = 'abccbab' s = 'aabbb' print('s=%s' % (s,), file = sys.stderr) for p in palindrome_gen(s): print(p, file = sys.stderr) #test() #exit() modulo = pow(10, 9) + 7 n,q = input().strip().split(' ') n,q = [int(n),int(q)] aa = [c for c in input().strip()] for a0 in range(q): ss = input().split() if ss[0] == '1': i, j, t = map(int, ss[1:]) rearrange(aa, i, j + 1, t) elif ss[0] == '2': i, j = map(int, ss[1:]) print(count(aa, i, j + 1, modulo))