N, Q = map(int, input().split())
S = input()
for _ in range(Q):
    L, R, K = map(int, input().split())
    X = S[L-1:R]
    while True:
        if '0'*K in X:
            X = X.replace('0'*K, '1'*(K-1))
        elif '1'*K in X:
            X = X.replace('1'*K, '0'*(K-1))
        else:
            break
    print(len(X))