#include <bits/stdc++.h>
using namespace std;
int millis() {
  static auto s = chrono::system_clock::now();
  chrono::duration<double> d = chrono::system_clock::now() - s;
  return 1e3 * d.count();
}
int const N = 560560;
long double const PI = acos(-1.);
inline void cmul(long double &x, long double &y, long double wx,
                 long double wy) {
  long double newx = x * wx - y * wy;
  y = y * wx + x * wy;
  x = newx;
}
long double wx[N], wy[N];
int bitrev[N];
void fft(long double *x, long double *y, int n, bool inv) {
  for (int i = 0; i < n; ++i) {
    if (i < bitrev[i]) {
      swap(x[i], x[bitrev[i]]);
      swap(y[i], y[bitrev[i]]);
    }
  }
  for (int len = 2; len <= n; len *= 2) {
    int s = n / len;
    for (int i = 0; i < n; i += len) {
      for (int q = 0, j = i, k = i + len / 2; k < i + len; q += s, ++j, ++k) {
        long double cx = x[k], cy = y[k];
        cmul(cx, cy, wx[q], inv ? -wy[q] : wy[q]);
        x[k] = x[j] - cx;
        y[k] = y[j] - cy;
        x[j] += cx;
        y[j] += cy;
      }
    }
  }
  if (inv) {
    for (int i = 0; i < n; ++i) {
      x[i] /= n;
      y[i] /= n;
    }
  }
}
int const C = 7006;
int const LEN = 200200;
int pre[LEN / C][LEN];
char a[LEN], b[LEN];
int main() {
  millis();
  scanf("%s%s", a, b);
  int alen = strlen(a);
  int blen = strlen(b);
  int n = 1, logn = 0;
  while (n < blen + C) {
    n *= 2;
    ++logn;
  }
  bitrev[0] = 0;
  for (int i = 1; i < n; ++i) {
    bitrev[i] = bitrev[i >> 1] >> 1 | (i & 1) << (logn - 1);
  }
  for (int i = 0; i < n; ++i) {
    long double ang = 2 * PI * i / n;
    wx[i] = cosl(ang);
    wy[i] = sinl(ang);
  }
  static long double bx[N], by[N];
  for (int i = 0; i < blen; ++i) {
    bx[i] = b[i] == '1' ? 1 : -1;
  }
  fft(bx, by, n, 0);
  for (int i = 0; i < alen; i += C) {
    int cur = min(C, alen - i);
    static long double ax[N], ay[N];
    fill_n(ax, n, 0);
    fill_n(ay, n, 0);
    for (int j = 0; j < cur; ++j) {
      ax[j] = a[i + cur - 1 - j] == '1' ? 1 : -1;
    }
    fft(ax, ay, n, 0);
    for (int j = 0; j < n; ++j) {
      cmul(ax[j], ay[j], bx[j], by[j]);
    }
    fft(ax, ay, n, 1);
    for (int j = 0; j + cur <= blen; ++j) {
      pre[i / C][j] = (cur - (int)round(ax[cur - 1 + j])) / 2;
    }
  }
  int q;
  scanf("%d", &q);
  for (int it = 0; it < q; ++it) {
    int p1, p2, len;
    scanf("%d%d%d", &p1, &p2, &len);
    int e1 = p1 + len;
    int ans = 0;
    for (int i = 0; i < alen; i += C) {
      int j = min(i + C, alen);
      if (j <= p1 || e1 <= i) continue;
      if (p1 <= i && j <= e1) {
        ans += pre[i / C][i + (p2 - p1)];
        continue;
      }
      for (int x = max(i, p1); x < j && x < e1; ++x) {
        ans += a[x] != b[x + (p2 - p1)] ? 1 : 0;
      }
    }
    cout << ans << '\n';
  }
}
