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 comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / gcd(a, b)) * b;
}
template <class T, class X>
inline bool getbit(T a, X i) {
  T t = 1;
  return ((a & (t << i)) > 0);
}
template <class T, class X>
inline T setbit(T a, X i) {
  T t = 1;
  return (a | (t << i));
}
template <class T, class X>
inline T resetbit(T a, X i) {
  T t = 1;
  return (a & (~(t << i)));
}
inline long long getnum() {
  char c = getchar();
  long long num, sign = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') sign = -1;
  for (num = 0; c >= '0' && c <= '9';) {
    c -= '0';
    num = num * 10 + c;
    c = getchar();
  }
  return num * sign;
}
inline long long power(long long a, long long b) {
  long long multiply = 1;
  for (int i = (0); i < (b); i++) {
    multiply *= a;
  }
  return multiply;
}
const int MAXN = (1 << 21);
struct complex_base {
  double x, y;
  complex_base(double _x = 0, double _y = 0) {
    x = _x;
    y = _y;
  }
  friend complex_base operator-(const complex_base &a, const complex_base &b) {
    return complex_base(a.x - b.x, a.y - b.y);
  }
  friend complex_base operator+(const complex_base &a, const complex_base &b) {
    return complex_base(a.x + b.x, a.y + b.y);
  }
  friend complex_base operator*(const complex_base &a, const complex_base &b) {
    return complex_base(a.x * b.x - a.y * b.y, a.y * b.x + b.y * a.x);
  }
  friend void operator/=(complex_base &a, const double &P) {
    a.x /= P;
    a.y /= P;
  }
};
int bit_rev[MAXN];
void fft(complex_base *a, int lg) {
  int n = (1 << lg);
  for (int i = 1; i < n; i++) {
    bit_rev[i] = (bit_rev[i >> 1] >> 1) | ((i & 1) << (lg - 1));
    if (bit_rev[i] < i) swap(a[i], a[bit_rev[i]]);
  }
  for (int len = 2; len <= n; len <<= 1) {
    double ang = 2 * acos(-1) / len;
    complex_base w(1, 0), wn(cos(ang), sin(ang));
    for (int j = 0; j < (len >> 1); j++, w = w * wn)
      for (int i = 0; i < n; i += len) {
        complex_base u = a[i + j], v = w * a[i + j + (len >> 1)];
        a[i + j] = u + v;
        a[i + j + (len >> 1)] = u - v;
      }
  }
}
void inv_fft(complex_base *a, int lg) {
  int n = (1 << lg);
  for (int i = 1; i < n; i++) {
    bit_rev[i] = (bit_rev[i >> 1] >> 1) | ((i & 1) << (lg - 1));
    if (bit_rev[i] < i) swap(a[i], a[bit_rev[i]]);
  }
  for (int len = 2; len <= n; len <<= 1) {
    double ang = -2 * acos(-1) / len;
    complex_base w(1, 0), wn(cos(ang), sin(ang));
    for (int j = 0; j < (len >> 1); j++, w = w * wn)
      for (int i = 0; i < n; i += len) {
        complex_base u = a[i + j], v = w * a[i + j + (len >> 1)];
        a[i + j] = u + v;
        a[i + j + (len >> 1)] = u - v;
      }
  }
  for (int i = 0; i < n; i++) a[i] /= n;
}
complex_base A[MAXN], B[MAXN];
vector<int> mult(vector<int> a, vector<int> b) {
  int lg = 0;
  while ((1 << lg) < (a.size() + b.size())) ++lg;
  for (int i = 0; i < (1 << lg); i++) A[i] = B[i] = complex_base(0, 0);
  for (int i = 0; i < (int)a.size(); i++) A[i] = complex_base(a[i], 0);
  for (int i = 0; i < (int)b.size(); i++) B[i] = complex_base(b[i], 0);
  fft(A, lg);
  fft(B, lg);
  for (int i = 0; i < (1 << lg); i++) A[i] = A[i] * B[i];
  inv_fft(A, lg);
  vector<int> ans(a.size() + b.size(), 0);
  for (int i = 0; i < (int)ans.size(); i++) ans[i] = (int)(A[i].x + 0.5);
  return ans;
}
const int BLOCK = 64;
const int blocksz = 1 << 13;
bitset<BLOCK> chunks[2 * 100005], chunkt[2 * 100005];
vector<int> a, blocks[450];
string s, t;
vector<int> hamming(int l, int r) {
  vector<int> b;
  int n = s.size(), m = r - l + 1;
  for (int i = (r); i >= (l); i--) {
    if (t[i] == '1')
      b.push_back(1);
    else
      b.push_back(-1);
  }
  vector<int> c = mult(a, b), ret;
  for (int i = 0; (i + m) <= n; i++) ret.push_back(m - (c[i + m - 1] + m) / 2);
  return ret;
}
int handle(int sx, int sy, int tx, int ty) {
  int ret = 0, i, j;
  for (i = sx, j = tx;; i += BLOCK, j += BLOCK) {
    if (i + BLOCK - 1 > sy) break;
    bitset<BLOCK> temp = chunks[i] ^ chunkt[j];
    ret += temp.count();
  }
  if (i <= sy) {
    for (int k = i, l = j; k <= sy, l <= ty; k++, l++) ret += (s[k] != t[l]);
  }
  return ret;
}
int handleBlocks(int sx, int sy, int tx, int l, int r) {
  int ret = 0;
  int pos = sx + l * blocksz - tx;
  for (int i = l; i <= r; i++) {
    if (pos + blocksz - 1 > sy) break;
    ret += blocks[i][pos];
    pos += blocksz;
  }
  return ret;
}
int findAns(int sx, int sy, int tx, int ty) {
  int ret = 0;
  int l = tx / blocksz + 1;
  int r = ty / blocksz - 1;
  if (l + 1 < r) {
    int pos1 = sx + l * blocksz - tx;
    int pos2 = sy - (ty - (r + 1) * blocksz);
    ret = handle(sx, pos1 - 1, tx, l * blocksz - 1);
    ret += handle(pos2, sy, (r + 1) * blocksz, ty);
    ret += handleBlocks(sx, sy, tx, l, r);
  } else {
    ret = handle(sx, sy, tx, ty);
  }
  return ret;
}
void handle() {
  int q, x, y, len;
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d%d", &x, &y, &len);
    int sx = x, sy = x + len - 1;
    int tx = y, ty = y + len - 1;
    int out = findAns(sx, sy, tx, ty);
    printf("%d\n", out);
  }
}
void solve() {
  int m = t.size(), last = 0;
  int blockcnt = (m - 1) / blocksz;
  for (int i = 0; i < m; i += blocksz) {
    blocks[i / blocksz] = hamming(i, min(m - 1, i + blocksz - 1));
    last = min(i + blocksz - 1, m - 1);
  }
  if (last != m - 1) blocks[blockcnt] = hamming(last, m - 1);
  for (int i = 0; i + BLOCK - 1 < s.size(); i++) {
    for (int j = i; j <= i + BLOCK - 1; j++) {
      if (s[j] == '1') chunks[i].set(BLOCK - 1 - j + i);
    }
  }
  for (int i = 0; i + BLOCK - 1 < t.size(); i++) {
    for (int j = i; j <= i + BLOCK - 1; j++) {
      if (t[j] == '1') chunkt[i].set(BLOCK - 1 - j + i);
    }
  }
  handle();
}
int main() {
  int test, cases = 1;
  cin >> s >> t;
  for (int i = (0); i < (s.size()); i++) {
    if (s[i] == '1')
      a.push_back(1);
    else
      a.push_back(-1);
  }
  solve();
  return 0;
}