Problem: There is a simple way to create hard tasks: take one simple problem as the query, and try to find an algorithm that can solve it faster than bruteforce. This kind of tasks usually appears in OI contest, and usually involves data structures.

Let's try to create a task, for example, we take the "Hamming distance problem": for two binary strings s and t with the same length, the Hamming distance between them is the number of positions at which the corresponding symbols are different. For example, the Hamming distance between "00111" and "10101" is 2 (the different symbols are marked with bold).

We use the Hamming distance problem as a query in the following way: you are given two strings a and b and several queries. Each query will be: what is the Hamming distance between two strings ap1ap1 + 1...ap1 + len - 1 and bp2bp2 + 1...bp2 + len - 1?

Note, that in this problem the strings are zero-based, that is s = s0s1... s|s| - 1.

Input

The first line contains a string a (1 ≤ |a| ≤ 200000). The second line contains a string b (1 ≤ |b| ≤ 200000). Each character of both strings is either "0" or "1".

The third line contains an integer q (1 ≤ q ≤ 400000) — the number of queries. Each of the following q lines contains three integers: p1, p2 and len (0 ≤ p1 ≤ |a| - len; 0 ≤ p2 ≤ |b| - len), these numbers denote the parameters of the current query.

Output

Output q integers — the answers for the queries.

Examples

Input

101010
11110000
3
0 0 3
2 3 4
5 7 1


Output

1
1
0


Input

10001010101011001010100101010011010
101010100101001010100100101010
5
0 0 12
3 9 7
6 4 15
12 15 10
13 3 20


Output

5
4
3
5
13

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 250000;
const int BLOCK = 10000;
const int BIT = 64;
const long double PI = acos(0.0) * 2.0;
inline void FFT(vector<complex<double> >& a, bool inverse) {
  int n = a.size();
  for (int i = 0, j = 0; i < n; i++) {
    if (j > i) swap(a[i], a[j]);
    int k = n;
    while (j & (k >>= 1)) j &= ~k;
    j |= k;
  }
  double pi = inverse ? -PI : PI;
  for (int step = 1; step < n; step <<= 1) {
    double alpha = pi / step;
    for (int k = 0; k < step; k++) {
      complex<double> omegak = exp(complex<double>(0, alpha * k));
      for (int Ek = k; Ek < n; Ek += step << 1) {
        int Ok = Ek + step;
        complex<double> t = omegak * a[Ok];
        a[Ok] = a[Ek] - t;
        a[Ek] += t;
      }
    }
  }
  if (inverse)
    for (int i = 0; i < n; i++) a[i] /= n;
}
inline vector<double> operator*(const vector<double>& v1,
                                const vector<double>& v2) {
  int s1 = v1.size(), s2 = v2.size(), S = 2;
  while (S < s1 + s2) S <<= 1;
  vector<complex<double> > a(S, 0), b(S, 0);
  for (int i = 0; i < s1; i++) a[i] = v1[i];
  FFT(a, false);
  for (int i = 0; i < s2; i++) b[i] = v2[i];
  FFT(b, false);
  for (int i = 0; i < S; i++) a[i] *= b[i];
  FFT(a, true);
  vector<double> res(s1 + s2 - 1);
  for (int i = 0; i < s1 + s2 - 1; i++) res[i] = a[i].real();
  return res;
}
char a[MAXN], b[MAXN];
vector<unsigned long long> A[BIT], B[BIT];
int cnt[200][MAXN];
int lena, lenb;
double trans(int x) {
  if (x == 0)
    return -1;
  else
    return 1;
}
vector<double> X, Y, Z;
void work(int l, int r) {
  X.clear();
  for (int i = l; i <= r; i++) X.push_back(trans(a[i] - '0'));
  Z = X * Y;
  int index = l / BLOCK;
  for (int i = BLOCK - 1; i < lenb; i++) {
    cnt[index][lenb - (i + 1)] = (BLOCK - round(Z[i])) / 2;
  }
}
int force(int l1, int r1, int l2, int r2) {
  if (l1 > r1 || l2 > r2) return 0;
  int res = 0;
  int index1 = (l1 - (l1 % BIT)) / BIT;
  int index2 = (l2 - (l2 % BIT)) / BIT;
  int x1 = l1 % BIT;
  int x2 = l2 % BIT;
  for (; l1 + BIT <= r1; l1 += BIT, l2 += BIT) {
    res += __builtin_popcountll(A[x1][index1] ^ B[x2][index2]);
    index1++;
    index2++;
  }
  unsigned long long q = BIT - r1 + l1 - 1;
  res += __builtin_popcountll((A[x1][index1] >> q) ^ (B[x2][index2] >> q));
  return res;
}
int main() {
  scanf("%s", a);
  scanf("%s", b);
  lena = strlen(a);
  lenb = strlen(b);
  for (int x = 0; x < BIT; x++) {
    for (int i = x; i < lena; i += BIT) {
      unsigned long long tmp = 0;
      for (int k = i; k < i + BIT && k < lena; k++) {
        tmp |= (unsigned long long)(a[k] - '0') << (i + BIT - 1 - k);
      }
      A[x].push_back(tmp);
    }
  }
  for (int x = 0; x < BIT; x++) {
    for (int i = x; i < lenb; i += BIT) {
      unsigned long long tmp = 0;
      for (int k = i; k < i + BIT && k < lenb; k++) {
        tmp |= (unsigned long long)(b[k] - '0') << (i + BIT - 1 - k);
      }
      B[x].push_back(tmp);
    }
  }
  for (int i = lenb - 1; i >= 0; i--) Y.push_back(trans(b[i] - '0'));
  int q, p1, p2, len;
  scanf("%d", &q);
  for (int i = BLOCK - 1; i < lena; i += BLOCK) work(i - BLOCK + 1, i);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d%d", &p1, &p2, &len);
    int e1 = p1 + len - 1;
    int e2 = p2 + len - 1;
    int ans = 0;
    int t1 = ((p1 - 1) / BLOCK + 1) * BLOCK;
    int l = t1 - p1;
    if (t1 <= e1) {
      ans += force(p1, p1 + l - 1, p2, p2 + l - 1);
      p1 += l;
      p2 += l;
    } else {
      ans += force(p1, e1, p2, e2);
      p1 = e1 + 1;
      p2 = e2 + 1;
    }
    int t2 = (e1 + 1) / BLOCK * BLOCK - 1;
    l = e1 - t2;
    if (t2 >= p1) {
      ans += force(t2 + 1, t2 + l, e2 - l + 1, e2);
      e1 -= l;
      e2 -= l;
    } else {
      ans += force(p1, e1, p2, e2);
      e1 = p1 - 1;
      e2 = p2 - 1;
    }
    if (e1 > p1) {
      int index = p1 / BLOCK;
      int t = (e1 + 1 - p1) / BLOCK;
      for (int k = index; k < index + t; k++) {
        ans += cnt[k][p2 + (k - index) * BLOCK];
      }
    }
    cout << ans << endl;
  }
}