#include <bits/stdc++.h>
const double pi = atan(1.0) * 4;
struct Complex {
  double x, y;
  Complex(double _x = 0, double _y = 0) : x(_x), y(_y) {}
  Complex operator+(Complex &tt) { return Complex(x + tt.x, y + tt.y); }
  Complex operator-(Complex &tt) { return Complex(x - tt.x, y - tt.y); }
  Complex operator*(Complex &tt) {
    return Complex(x * tt.x - y * tt.y, x * tt.y + y * tt.x);
  }
};
void fft(Complex *A, int n, int rev) {
  for (int i = 1, j = 0; i < n; ++i) {
    for (int k = n >> 1; k > (j ^= k); k >>= 1)
      ;
    if (i < j) std::swap(A[i], A[j]);
  }
  for (int m = 2; m <= n; m <<= 1) {
    Complex wm(cos(2 * pi * rev / m), sin(2 * pi * rev / m));
    for (int i = 0; i < n; i += m) {
      Complex w(1., 0.);
      for (int j = i; j < i + m / 2; ++j) {
        Complex t = w * A[j + m / 2];
        A[j + m / 2] = A[j] - t;
        A[j] = A[j] + t;
        w = w * wm;
      }
    }
  }
  if (rev == -1) {
    for (int i = 0; i < n; ++i) {
      A[i].x /= n;
      A[i].y /= n;
    }
  }
}
const int N = 200000 + 5;
const int Sqrt = 3000 + 5;
char str[N];
int A[N], B[N], n, m;
int table[N / Sqrt][N];
void prepare() {
  static Complex p1[N << 2], p2[N << 2];
  for (int i = 0; i < m; ++i) {
    p2[i] = Complex(B[m - 1 - i], !B[m - 1 - i]);
  }
  int L = 1;
  while (L < m + Sqrt) L <<= 1;
  fft(p2, L, 1);
  for (int i = 0, id = 0; i + Sqrt <= n; i += Sqrt, ++id) {
    for (int j = Sqrt; j < L; ++j) {
      p1[j] = Complex(0., 0.);
    }
    for (int j = 0; j < Sqrt; ++j) {
      p1[j] = Complex(!A[i + j], A[i + j]);
    }
    fft(p1, L, 1);
    for (int j = 0; j < L; ++j) {
      p1[j] = p1[j] * p2[j];
    }
    fft(p1, L, -1);
    for (int j = 0; j < m; ++j) {
      table[id][m - 1 - j] = Sqrt - int(p1[j].y + .5);
    }
  }
}
inline void read(int &x) {
  char c;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    ;
  for (x = 0; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
}
int calc(int a, int b, int len) {
  int ret = 0;
  while (a % Sqrt != 0 && len) {
    ret += A[a] != B[b];
    a++;
    b++;
    len--;
  }
  int i;
  for (i = 0; i + Sqrt <= len; i += Sqrt) {
    int id = (a + i) / Sqrt;
    ret += table[id][b + i];
  }
  for (; i < len; ++i) {
    ret += A[a + i] != B[b + i];
  }
  return ret;
}
int main() {
  scanf("%s", str);
  n = strlen(str);
  for (int i = 0; i < n; ++i) {
    A[i] = str[i] - '0';
  }
  scanf("%s", str);
  m = strlen(str);
  for (int i = 0; i < m; ++i) {
    B[i] = str[i] - '0';
  }
  prepare();
  int nq;
  read(nq);
  while (nq--) {
    int a, b, len;
    read(a), read(b), read(len);
    printf("%d\n", calc(a, b, len));
  }
  return 0;
}
