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>
#pragma warning(disable : 4244 4267 4018 4996 4800)
using namespace std;
istream &in = cin;
ostream &out = cout;
namespace fft {
map<int, vector<int>> revbits;
map<pair<int, bool>, vector<complex<double>>> w_pow_cache;
double const pi = acos(-1.);
void fft_impl(vector<complex<double>> &v, bool invert) {
  int n = v.size();
  vector<int> &rev = revbits[n];
  if (rev.empty()) {
    int logn = 0;
    while ((1 << logn) < n) ++logn;
    rev.resize(n);
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < logn; ++j)
        if (i & (1 << j)) rev[i] |= 1 << (logn - 1 - j);
    }
  }
  for (int i = 0; i < n; ++i) {
    if (i < rev[i]) swap(v[i], v[rev[i]]);
  }
  complex<double> *p = &v[0];
  for (int len = 2; len <= n; len <<= 1) {
    int len2 = len >> 1;
    vector<complex<double>> &w_pow = w_pow_cache[make_pair(len2, invert)];
    if (w_pow.empty()) {
      double ang = (invert ? -1 : 1) * 2 * pi / len;
      complex<double> w(cos(ang), sin(ang));
      w_pow.resize(len2);
      w_pow[0] = complex<double>(1, 0);
      for (int i = 1; i < len2; ++i) {
        w_pow[i] = w_pow[i - 1];
        w_pow[i] *= w;
      }
    }
    for (int i = 0; i < n; i += len) {
      complex<double> *pu = p + i, *pv = pu + len2, *pu_end = pv,
                      *pw = &w_pow[0];
      for (; pu != pu_end; ++pu, ++pv, ++pw) {
        complex<double> t = *pv;
        t *= *pw;
        *pv = *pu;
        *pv -= t;
        *pu += t;
      }
    }
  }
}
vector<double> fft(vector<double> const &p, vector<double> const &q) {
  int n = 1;
  for (; n < p.size() + q.size(); n <<= 1)
    ;
  vector<complex<double>> a(n), b(n);
  for (int i = 0; i < p.size(); ++i) a[i] = complex<double>(p[i]);
  for (int i = 0; i < q.size(); ++i) b[i] = complex<double>(q[i]);
  fft_impl(a, false);
  fft_impl(b, false);
  for (int i = 0; i < n; ++i) a[i] *= b[i];
  fft_impl(a, true);
  vector<double> res(n);
  for (int i = 0; i < n; ++i) res[i] = real(a[i]) / n;
  return res;
}
}  // namespace fft
vector<char> read_vec() {
  string s;
  in >> s;
  vector<char> res(s.size());
  for (int i = 0; i < res.size(); ++i) res[i] = s[i] - '0';
  return res;
}
void convert(vector<double> &v) {
  for (auto &x : v)
    if (x == 0) x = -1;
}
vector<char> randvec() {
  vector<char> res(200000);
  for (auto &x : res) x = rand() % 2;
  return res;
}
vector<unsigned long long> toint(vector<char> const &v) {
  vector<unsigned long long> res;
  if (v.size() < 64) return res;
  unsigned long long cur = 0;
  res.reserve(v.size() - 63);
  for (int i = 0; i < 64; ++i) cur = (cur << 1) | v[i];
  res.push_back(cur);
  for (int i = 64; i < v.size(); ++i) {
    cur = (cur << 1) | v[i];
    res.push_back(cur);
  }
  return res;
}
int bitcount(unsigned i) {
  i = i - ((i >> 1) & 0x55555555);
  i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
  i = (i + (i >> 4)) & 0x0f0f0f0f;
  i = i + (i >> 8);
  i = i + (i >> 16);
  return i & 0x3f;
}
int main() {
  ios_base::sync_with_stdio(false);
  vector<char> a = read_vec(), b = read_vec();
  vector<double> bd(b.begin(), b.end());
  convert(bd);
  int block = 6900;
  vector<vector<double>> blockfft;
  vector<double> apart;
  vector<unsigned long long> ia = toint(a), ib = toint(b);
  for (int i = 0; i < a.size(); i += block) {
    int end = min<int>(a.size(), i + block);
    apart.assign(a.begin() + i, a.begin() + end);
    convert(apart);
    reverse((apart).begin(), (apart).end());
    blockfft.push_back(fft::fft(apart, bd));
  }
  int qnum;
  in >> qnum;
  unsigned long long mask32 = (1LL << 32) - 1;
  for (int q = 0; q < qnum; ++q) {
    int p1, p2, len, res = 0;
    in >> p1 >> p2 >> len;
    for (int idx = p1 / block;; ++idx) {
      int start = idx * block;
      int end = min<int>(a.size(), start + block);
      if (start >= p1 + len) break;
      if (start < p1 || end >= p1 + len) {
        int left1 = max(start, p1), right1 = min(end, p1 + len),
            left2 = p2 + left1 - p1;
        for (; left1 + 64 <= right1; left1 += 64, left2 += 64) {
          unsigned long long x = ia[left1] ^ ib[left2];
          res += bitcount(x >> 32) + bitcount(x & mask32);
        }
        for (; left1 < right1; ++left1, ++left2) res += a[left1] ^ b[left2];
      } else {
        res += (block - round(blockfft[idx][end - p1 - 1 + p2])) / 2;
      }
    }
    out << res << '\n';
  }
  return 0;
}