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;
template <class T>
inline void Read(T &x) {
  int f = 1;
  char t = getchar();
  while (t < '0' || t > '9') {
    if (t == '-') f = -1;
    t = getchar();
  }
  x = 0;
  while (t >= '0' && t <= '9') {
    x = x * 10 + t - '0';
    t = getchar();
  }
  x *= f;
}
template <class T>
inline void Write(T x) {
  static int q[35];
  int r = 0;
  do {
    q[++r] = x % 10;
    x /= 10;
  } while (x > 0);
  while (r > 0) putchar('0' + q[r--]);
  putchar('\n');
}
template <class T>
inline void chkmax(T &x, T y) {
  if (x < y) x = y;
}
template <class T>
inline void chkmin(T &x, T y) {
  if (x > y) x = y;
}
const int maxn = 340124;
const int maxl = 200005;
const int maxs = 110;
const double pi = acos(-1.0);
struct Complex {
  double x;
  double y;
  Complex() {}
  Complex(double x, double y) : x(x), y(y) {}
  inline Complex operator+(const Complex &rhs) {
    return Complex(x + rhs.x, y + rhs.y);
  }
  inline Complex operator-(const Complex &rhs) {
    return Complex(x - rhs.x, y - rhs.y);
  }
  inline Complex operator*(const Complex &rhs) {
    return Complex(x * rhs.x - y * rhs.y, x * rhs.y + y * rhs.x);
  }
};
int n;
int m;
char A[maxl];
char B[maxl];
bool flag;
void input() {
  scanf("%s", A + 1);
  scanf("%s", B + 1);
  n = strlen(A + 1);
  m = strlen(B + 1);
  for (int i = 1; i <= n; i++) A[i] -= '0';
  for (int i = 1; i <= m; i++) B[i] -= '0';
  if (n > m) {
    static char tmp[maxn];
    swap(n, m);
    memcpy(tmp, A, sizeof(A));
    memcpy(A, B, sizeof(A));
    memcpy(B, tmp, sizeof(B));
    flag = true;
  }
}
int blockn;
int block_sz;
int belong[maxl];
int belong2[maxl];
int diff[maxn][maxs];
int N;
int L;
int rev[maxn];
Complex bit[maxn];
void init(int len) {
  N = 1, L = 0;
  while (N < len) {
    N <<= 1;
    L++;
  }
  Complex d = Complex(sin(2 * pi / N), cos(2 * pi / N));
  bit[0] = Complex(1, 0);
  for (int i = 1; i <= N; i++) {
    bit[i] = bit[i - 1] * d;
  }
  for (int i = 0; i < N; i++) {
    rev[i] = rev[i >> 1] >> 1 | ((i & 1) << (L - 1));
  }
}
void dft(Complex *res, int flag) {
  Complex x, y;
  for (int i = 0; i < N; i++) {
    if (rev[i] > i) {
      swap(res[rev[i]], res[i]);
    }
  }
  for (int k = 1; k < N; k <<= 1) {
    for (int s = 0; s < N; s += (k << 1)) {
      for (int i = 0; i < k; i++) {
        x = res[s + i], y = res[s + k + i];
        if (flag == 1)
          y = y * bit[N / (k << 1) * i];
        else
          y = y * bit[N - N / (k << 1) * i];
        res[s + i] = x + y;
        res[s + k + i] = x - y;
      }
    }
  }
  if (flag == -1) {
    for (int i = 0; i < N; i++) {
      res[i].x /= N;
    }
  }
}
void getdiff(int s, int len, int idx) {
  static Complex a[maxn];
  static Complex b[maxn];
  static Complex c[maxn];
  for (int i = 0; i < len; i++) a[i].x = A[s + i] ? 1 : -1, a[i].y = 0;
  for (int i = len; i < N; i++) a[i].x = a[i].y = 0;
  for (int i = 0; i < m; i++) b[i].x = B[i + 1] ? 1 : -1, b[i].y = 0;
  for (int i = m; i < N; i++) b[i].x = b[i].y = 0;
  reverse(b, b + N);
  dft(a, 1);
  dft(b, 1);
  for (int i = 0; i < N; i++) c[i] = a[i] * b[i];
  dft(c, -1);
  for (int i = 1; i + len - 1 <= m; i++) {
    diff[i][idx] = len - ((int)(c[N - i].x + 0.5) + len) / 2;
  }
}
void prepare() {
  block_sz = sqrt(n * log2(n));
  if (m > 10000) {
    block_sz = (double)block_sz * 2.8;
  }
  chkmax(block_sz, 1);
  blockn = 1;
  for (int i = 1; i <= n; i++) {
    belong[i] = blockn;
    if (i % block_sz == 0 && i < n) blockn++;
  }
  init(m + block_sz);
  for (int i = 1; i <= blockn; i++) {
    int s = (i - 1) * block_sz + 1;
    int len = min(block_sz, n - s + 1);
    getdiff(s, len, belong[s]);
  }
}
int hamdist(int s1, int s2, int len) {
  int st;
  int ed;
  int cur = 1;
  int res = 0;
  if ((s1 - 1) % block_sz == 0)
    st = (s1 - 1) / block_sz + 1;
  else
    st = (s1 - 1) / block_sz + 2;
  if ((s1 + len - 1) % block_sz == 0)
    ed = ((s1 + len - 1) - 1) / block_sz + 1;
  else
    ed = ((s1 + len - 1) - 1) / block_sz;
  int stp = (st - 1) * block_sz + 1;
  while (cur <= len && s1 + cur - 1 < stp) {
    res += A[s1 + cur - 1] ^ B[s2 + cur - 1];
    cur++;
  }
  for (int i = st; i <= ed; i++) {
    res += diff[s2 + cur - 1][i];
    cur += block_sz;
  }
  while (cur <= len) {
    res += A[s1 + cur - 1] ^ B[s2 + cur - 1];
    cur++;
  }
  return res;
}
void solve() {
  int q;
  int len;
  int s1, s2;
  Read(q);
  while (q--) {
    Read(s1);
    Read(s2);
    Read(len);
    s1++;
    s2++;
    if (flag) swap(s1, s2);
    Write(hamdist(s1, s2, len));
  }
}
int main() {
  input();
  prepare();
  solve();
  return 0;
}