#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:255000000")
bool firstout = 1;
template <class T>
T &minn(T &a, T b) {
  if (b < a) a = b;
  return a;
}
template <class T>
T &maxx(T &a, T b) {
  if (a < b) a = b;
  return a;
}
int &madd(int &a, int b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
  return a;
}
int &msub(int &a, int b) {
  a -= b;
  if (a < 0) a += 1000000007;
  return a;
}
int &mmult(int &a, int b) { return a = (long long)a * b % 1000000007; }
int mdiv(long long a, long long b, long long m) {
  a = (a % m + m) % m;
  b = (b % m + m) % m;
  if (a % b == 0) return a / b;
  return (a + m * mdiv(-a, m, b)) / b;
}
const double pi = acos(-1.);
complex<double> X[201234 * 4], Y[201234 * 4], W[201234 * 4];
template <class T>
void fft(T *x, complex<double> *X, int n, int d = 1) {
  if (n == 1) {
    *X = *x;
    return;
  }
  n /= 2;
  fft(x, X, n, d * 2);
  fft(x + d, X + n, n, d * 2);
  int i;
  complex<double> p;
  for (i = 0; i < n; ++i)
    X[i + n] = X[i] - (p = X[i + n] * W[i * d]), X[i] += p;
}
void fastmul(int *x, int nx, int *y, int ny, int *r) {
  int n = nx + ny;
  for (; n & (n - 1); ++n)
    ;
  int i;
  for (i = nx; i < n; ++i) x[i] = 0;
  for (i = ny; i < n; ++i) y[i] = 0;
  for (i = 0; i < n; ++i) W[i] = polar(1., 2. * i * pi / n);
  fft(x, X, n);
  fft(y, Y, n);
  for (i = 0; i < n; ++i) Y[i] *= X[i], W[i] = polar(1., -2. * i * pi / n);
  fft(Y, X, n);
  for (i = 0; i < n; ++i)
    r[i] = (int)(real(X[i]) / n + 0.5) - (real(X[i]) / n < -0.5);
}
int n, m, q, mm;
int A[201234], B[201234];
char SA[201234], SB[201234];
int NB[1 << 30 / 2];
int nbmask = (1 << 30 / 2) - 1;
int halfM = 30 / 2;
int L[25], R[25];
int LR[25][201234];
int nn;
int B1[201234 * 4], B2[201234 * 4];
int AL[201234 * 4];
int C[201234 * 4];
int nb(int a) { return NB[a & nbmask] + NB[a >> halfM]; }
int calc(int i, int j, int l) {
  int res = 0;
  for (; l >= 30; l -= 30, i += 30, j += 30) res += nb(A[i] ^ B[j]);
  for (; l; --l, ++i, ++j) res += A[i] & 1 ^ B[j] & 1;
  return res;
}
int main() {
  int i, j, k;
  char c;
  int a, d;
  for (i = (0); i < (1 << 30 / 2); ++i) {
    a = i;
    int &res = NB[i];
    res = 0;
    for (; a; a &= a - 1) ++res;
  }
  int ts;
  for (ts = 1; scanf("%"
                     "s",
                     &(SA)) > 0;
       ++ts) {
    scanf(
        "%"
        "s",
        &(SB));
    n = strlen(SA);
    m = strlen(SB);
    for (i = (0); i < (n); ++i) SA[i] -= '0';
    for (i = (0); i < (m); ++i) SB[i] -= '0';
    for (i = (0); i < (n); ++i) {
      int &res = A[i];
      res = 0;
      for (k = (0); k < (30); ++k) {
        j = i + k;
        if (j < n) res |= SA[j] << k;
      }
    }
    for (i = (0); i < (m); ++i) {
      int &res = B[i];
      res = 0;
      for (k = (0); k < (30); ++k) {
        j = i + k;
        if (j < m) res |= SB[j] << k;
      }
    }
    for (i = (0); i < (m); ++i) B1[i] = B[i] & 1, B2[i] = !B1[i];
    mm = min(n, 25);
    nn = n / mm;
    for (k = (0); k < (mm); ++k) {
      L[k] = k * nn;
      R[k] = L[k] + nn;
      if (k == mm - 1) R[k] = n;
      nn = R[k] - L[k];
      for (i = (0); i < (m); ++i) LR[k][i] = 0;
      for (i = (0); i < (nn); ++i) AL[i] = A[R[k] - i - 1] & 1;
      fastmul(AL, nn, B2, m, C);
      for (i = (0); i < (m); ++i) LR[k][i] += C[i + nn - 1];
      for (i = (0); i < (nn); ++i) AL[i] = !AL[i];
      fastmul(AL, nn, B1, m, C);
      for (i = (0); i < (m); ++i) LR[k][i] += C[i + nn - 1];
    }
    scanf(
        "%"
        "d",
        &(q));
    for (; q--;) {
      int l;
      scanf(
          "%"
          "d",
          &(i));
      scanf(
          "%"
          "d",
          &(j));
      scanf(
          "%"
          "d",
          &(l));
      int mn = 1012345678, mx = 0;
      int res = 0;
      for (k = (0); k < (mm); ++k)
        if (i <= L[k] && R[k] <= i + l) {
          minn(mn, L[k]);
          maxx(mx, R[k]);
          res += LR[k][j + L[k] - i];
        }
      if (mn < mx) {
        res += calc(i, j, mn - i);
        res += calc(i + (mx - i), j + (mx - i), l - (mx - i));
      } else
        res += calc(i, j, l);
      printf(
          "%"
          "d",
          (res));
      printf("\n"), firstout = 1;
    }
  }
  return 0;
}
