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 {
struct cd {
  cd(double real = 0, double imag = 0) : real(real), imag(imag) {}
  cd &operator+=(cd const &rhs) {
    real += rhs.real;
    imag += rhs.imag;
    return *this;
  }
  cd &operator-=(cd const &rhs) {
    real -= rhs.real;
    imag -= rhs.imag;
    return *this;
  }
  cd &operator*=(cd const &rhs) {
    double r = real * rhs.real - imag * rhs.imag;
    imag = real * rhs.imag + imag * rhs.real;
    real = r;
    return *this;
  }
  bool operator==(cd const &rhs) {
    return real == rhs.real && imag == rhs.imag;
  }
  double real, imag;
};
double real(cd const &r) { return r.real; }
map<int, vector<int>> revbits;
map<pair<int, bool>, vector<cd>> w_pow_cache;
double const pi = acos(-1.);
void fft_impl(vector<cd> &v, bool invert) {
  int n = v.size();
  cd *p = &v[0];
  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]]);
  }
  for (int len = 2; len <= n; len <<= 1) {
    int len2 = len >> 1;
    vector<cd> &w_pow = w_pow_cache[make_pair(len2, invert)];
    if (w_pow.empty()) {
      double ang = (invert ? -1 : 1) * 2 * pi / len;
      cd w(cos(ang), sin(ang));
      w_pow.resize(len2);
      w_pow[0] = cd(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) {
      cd *pu = p + i, *pv = p + i + len2, *pu_end = p + i + len2,
         *pw = &w_pow[0];
      for (; pu != pu_end; ++pu, ++pv, ++pw) {
        cd 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<cd> a(n), b(n);
  for (int i = 0; i < p.size(); ++i) a[i] = cd(p[i]);
  for (int i = 0; i < q.size(); ++i) b[i] = cd(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> toint(vector<char> const &v) {
  vector<unsigned> res;
  if (v.size() < 32) return res;
  unsigned cur = 0;
  for (int i = 0; i < 32; ++i) cur = (cur << 1) | v[i];
  res.push_back(cur);
  for (int i = 32; i < v.size(); ++i) {
    cur = (cur << 1) | v[i];
    res.push_back(cur);
  }
  return res;
}
vector<int> cnt;
int bitcount(unsigned x) { return cnt[x & 65535] + cnt[x >> 16]; }
int main() {
  ios_base::sync_with_stdio(false);
  cnt.resize(65536);
  for (int i = 0; i < cnt.size(); ++i) {
    for (int j = 0; j < 16; ++j)
      if (i & (1 << j)) ++cnt[i];
  }
  vector<char> a = read_vec(), b = read_vec();
  vector<double> bd(b.begin(), b.end());
  convert(bd);
  int block = 8000;
  vector<vector<double>> blockfft;
  vector<double> apart;
  vector<unsigned> 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;
  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 + 32 <= right1; left1 += 32, left2 += 32)
          res += bitcount(ia[left1] ^ ib[left2]);
        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;
}