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;
namespace fft {
struct num {
  double x, y;
  num() { x = y = 0; }
  num(double x, double y) : x(x), y(y) {}
};
inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); }
inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); }
inline num operator*(num a, num b) {
  return num(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
}
inline num conj(num a) { return num(a.x, -a.y); }
int base = 1;
vector<num> roots = {{0, 0}, {1, 0}};
vector<int> rev = {0, 1};
const double PI = acosl(-1.0);
void ensure_base(int nbase) {
  if (nbase <= base) {
    return;
  }
  rev.resize(1 << nbase);
  for (int i = 0; i < (1 << nbase); i++) {
    rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));
  }
  roots.resize(1 << nbase);
  while (base < nbase) {
    double angle = 2 * PI / (1 << (base + 1));
    for (int i = 1 << (base - 1); i < (1 << base); i++) {
      roots[i << 1] = roots[i];
      double angle_i = angle * (2 * i + 1 - (1 << base));
      roots[(i << 1) + 1] = num(cos(angle_i), sin(angle_i));
    }
    base++;
  }
}
void fft(vector<num> &a, int n = -1) {
  if (n == -1) {
    n = a.size();
  }
  assert((n & (n - 1)) == 0);
  int zeros = __builtin_ctz(n);
  ensure_base(zeros);
  int shift = base - zeros;
  for (int i = 0; i < n; i++) {
    if (i < (rev[i] >> shift)) {
      swap(a[i], a[rev[i] >> shift]);
    }
  }
  for (int k = 1; k < n; k <<= 1) {
    for (int i = 0; i < n; i += 2 * k) {
      for (int j = 0; j < k; j++) {
        num z = a[i + j + k] * roots[j + k];
        a[i + j + k] = a[i + j] - z;
        a[i + j] = a[i + j] + z;
      }
    }
  }
}
vector<num> fa, fb;
vector<int> multiply(vector<int> &a, vector<int> &b) {
  int need = a.size() + b.size() - 1;
  int nbase = 0;
  while ((1 << nbase) < need) nbase++;
  ensure_base(nbase);
  int sz = 1 << nbase;
  if (sz > (int)fa.size()) {
    fa.resize(sz);
  }
  for (int i = 0; i < sz; i++) {
    int x = (i < (int)a.size() ? a[i] : 0);
    int y = (i < (int)b.size() ? b[i] : 0);
    fa[i] = num(x, y);
  }
  fft(fa, sz);
  num r(0, -0.25 / sz);
  for (int i = 0; i <= (sz >> 1); i++) {
    int j = (sz - i) & (sz - 1);
    num z = (fa[j] * fa[j] - conj(fa[i] * fa[i])) * r;
    if (i != j) {
      fa[j] = (fa[i] * fa[i] - conj(fa[j] * fa[j])) * r;
    }
    fa[i] = z;
  }
  fft(fa, sz);
  vector<int> res(need);
  for (int i = 0; i < need; i++) {
    res[i] = fa[i].x + (fa[i].x > 0 ? 0.5 : -0.5);
  }
  return res;
}
};  // namespace fft
const int N = 2e5 + 5;
const int K = 7000;
const int MASK = (1 << 16) - 1;
int n, m, q;
char a[N], b[N];
int cnt[N];
unsigned a1[32][N >> 5], a2[32][N >> 5];
vector<int> mul[N / K + 5];
int get(int l, int r, int len) {
  int ans = 0;
  while (len >= 32 and l % K != 1 and l % K and
         ((l + 32) % K > l % K or (l + 32) % K == 0)) {
    int w1 = (l - 1) & 31;
    int w2 = (r - 1) & 31;
    int x = (l - 1) >> 5;
    int y = (r - 1) >> 5;
    unsigned mask = a1[w1][x] ^ a2[w2][y];
    ans += cnt[mask & MASK] + cnt[mask >> 16];
    l += 32;
    r += 32;
    len -= 32;
  }
  while (len and l % K != 1) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  while (len >= K) {
    int id = (l - 1) / K;
    int i = m - 1 - (r - 1);
    ans += (K - mul[id][i]) / 2;
    l += K;
    r += K;
    len -= K;
  }
  while (len >= 32) {
    int w1 = (l - 1) & 31;
    int w2 = (r - 1) & 31;
    int x = (l - 1) >> 5;
    int y = (r - 1) >> 5;
    unsigned mask = a1[w1][x] ^ a2[w2][y];
    ans += cnt[mask & MASK] + cnt[mask >> 16];
    l += 32;
    r += 32;
    len -= 32;
  }
  while (len) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  return ans;
}
int main() {
  for (int i = 1; i < (1 << 16); i++) cnt[i] = cnt[i - (i & -i)] + 1;
  scanf("%s %s", a + 1, b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  for (int j = 0; j < 32; j++) {
    for (int i = 0; i + j < n; i++)
      if (a[i + j + 1] == '1') a1[j][i >> 5] |= 1 << (i & 31);
  }
  for (int j = 0; j < 32; j++) {
    for (int i = 0; i + j < m; i++)
      if (b[i + j + 1] == '1') a2[j][i >> 5] |= 1 << (i & 31);
  }
  auto upd = [&](char s[N], int n) {
    for (int i = 1; i <= n; i++) {
      if (s[i] == '1')
        s[i] = 1;
      else
        s[i] = -1;
    }
  };
  upd(a, n);
  upd(b, m);
  auto getVec = [&](char s[N], int l, int r) {
    vector<int> v;
    for (int i = l; i <= r; i++) {
      v.push_back(s[i]);
    }
    return v;
  };
  vector<int> vb = getVec(b, 1, m);
  reverse(vb.begin(), vb.end());
  for (int i = 1; i <= n; i += K) {
    int id = (i - 1) / K;
    int end = min(n, i + K - 1);
    vector<int> va = getVec(a, i, end);
    mul[id] = fft ::multiply(va, vb);
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int l, r, len;
    scanf("%d %d %d", &l, &r, &len);
    l++;
    r++;
    int res = get(l, r, len);
    printf("%d\n", res);
  }
  return 0;
}