#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const double pi = acos(-1);
const int bla = 2000;
struct cp {
  double r, i;
  cp(double R = 0, double I = 0) : r(R), i(I) {}
  cp operator+(const cp &tp) { return cp(r + tp.r, i + tp.i); }
  cp operator-(const cp &tp) { return cp(r - tp.r, i - tp.i); }
  cp operator*(const cp &tp) {
    return cp(r * tp.r - i * tp.i, i * tp.r + r * tp.i);
  }
};
char a[200005], b[200005];
int q, pos[200005], ed[1005], st[1005], n, m;
short d[105][200005];
cp ft[800005], A[800005], B[800005];
void FFT(cp a[], int n, int ty) {
  for (int i = 0; i < n; i++) {
    int j = 0;
    for (int m = 1, k = i; m < n; m <<= 1, j = (j << 1) | (k & 1), k >>= 1)
      ;
    if (i < j) swap(a[i], a[j]);
  }
  ft[0] = cp(1, 0);
  for (int m = 1; m < n; m <<= 1) {
    cp w = cp(cos(pi / m), ty * sin(pi / m));
    for (int i = 1; i < m; i++) ft[i] = ft[i - 1] * w;
    for (int k = 0; k < n; k += m << 1)
      for (int i = k; i < k + m; i++) {
        cp t0 = a[i], t1 = a[i + m] * ft[i - k];
        a[i] = t0 + t1, a[i + m] = t0 - t1;
      }
  }
  if (ty == -1)
    for (int i = 0; i < n; i++) a[i].r /= n;
}
void pre() {
  scanf("%s", a + 1);
  scanf("%s", b + 1);
  n = strlen(a + 1), m = strlen(b + 1);
  for (int i = 1; i <= n; i++) pos[i] = (i - 1) / bla + 1, ed[pos[i]] = i;
  for (int i = n; i >= 1; i--) st[pos[i]] = i;
  int len = 1 << (int)ceil(log2(bla + m + 1));
  for (int i = 1; i <= m; i++) B[i] = (b[i] == '1') ? 1 : -1;
  FFT(B, len, 1);
  int num = pos[n];
  for (int i = 1; i <= num; i++) {
    int l = st[i], r = ed[i];
    for (int j = r; j >= l; j--) A[r - j + 1] = (a[j] == '1') ? 1 : -1;
    FFT(A, len, 1);
    for (int j = 0; j < len; j++) A[j] = A[j] * B[j];
    FFT(A, len, -1);
    int sum = r - l + 1;
    for (int j = 1; j <= m; j++) {
      d[i][j] = (sum - (round)(A[j + bla].r)) / 2;
    }
    for (int j = 0; j < len; j++) A[j] = 0;
  }
}
int main() {
  pre();
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int p1, p2, len;
    scanf("%d%d%d", &p1, &p2, &len);
    p1++, p2++;
    if (pos[p1] == pos[p1 + len - 1]) {
      int ans = 0;
      for (int i = 0; i < len; i++) ans += (a[p1 + i] != b[p2 + i]);
      printf("%d\n", ans);
    } else {
      int ee = p1 + len - 1;
      int ans = 0;
      int L = pos[p1], R = pos[p1 + len - 1];
      for (int i = 0; i < ed[L] - p1 + 1; i++) ans += (a[p1 + i] != b[p2 + i]);
      p2 += ed[L] - p1 + 1;
      for (int i = L + 1; i < R; i++) {
        ans += d[i][p2];
        p2 += ed[i] - st[i] + 1;
      }
      for (int i = 0; i < ee - st[R] + 1; i++)
        ans += (a[st[R] + i] != b[p2 + i]);
      printf("%d\n", ans);
    }
  }
}
