Hamming distance queries

Given binary strings a and b, answer queries asking for the Hamming distance between a substring of a and a substring of b.

Medium5Prefix sumStringArrayBit manipulationInterviewNo attempts yetTime limit6sMemory limit512 MB

Problem

The Hamming distance between two binary strings ss and tt of equal length is the number of positions where the two values differ. For example, the Hamming distance between "00111" and "10101" is 2.

You are given binary strings aa and bb. Write a program that answers the following query.

  • p1 p2 len: print the Hamming distance between the substrings ap1ap1+1ap1+len1a_{p_1} a_{p_1+1} \ldots a_{p_1+len-1} and bp2bp2+1bp2+len1b_{p_2} b_{p_2+1} \ldots b_{p_2+len-1}.

String indices start at 0.

Input

The first line has the binary string aa and the second line has the binary string bb. The length of each string is a positive integer at most 200,000.

The third line has the number of queries qq (1q400,0001 \le q \le 400{,}000). Each of the next qq lines has one query as p1p_1, p2p_2, and lenlen separated by spaces (1len1 \le len, 0p1alen0 \le p_1 \le |a| - len, 0p2blen0 \le p_2 \le |b| - len).

Output

Print the answer to each query on its own line, in the order the queries are given.