#include <bits/stdc++.h>
#pragma GCC target("popcnt")
using namespace std;
const int N = 262144, BL = 4096, md = 998244353, K = N / BL + 2;
char a[N], b[N];
int rev[N * 2], lim, W[N], _ilim, n, ans[N * 2];
bitset<BL> sA[K], sB[K], prv[BL];
int QL0[N * 2], QR0[N * 2], QL1[N * 2], QR1[N * 2], q, F[N], G[N];
inline int pow(int a, int b) {
  int res = 1;
  for (; b; b >>= 1, a = (unsigned long long)a * a % md)
    if (b & 1) res = (unsigned long long)res * a % md;
  return res;
}
void init_() {
  for (int i = 1; i < N; i <<= 1) {
    const int g = pow(114514, (md - 1) / (i << 1));
    W[i] = 1;
    for (int j = 1; j < i; ++j)
      W[i + j] = (unsigned long long)W[i + (j - 1)] * g % md;
  }
  for (int i = 1; i <= N; i <<= 1)
    for (int j = 1; j < i; ++j)
      rev[i + j] = (rev[i + j / 2] >> 1) | ((j & 1) * (i / 2));
}
inline void init(int n) {
  for (lim = 1; lim < n; lim <<= 1)
    ;
  _ilim = pow(lim, md - 2);
}
void DFT(int* b) {
  static unsigned long long a[N];
  for (int i = 0; i < lim; ++i) a[i] = b[rev[i + lim]];
  for (int i = 1; i < lim; i <<= 1)
    for (int j = 0; j < lim; j += i << 1)
      for (int k = 0; k < i; ++k) {
        const unsigned long long x = a[j + k], y = a[j + k + i] * W[i + k] % md;
        a[j + k] += y, a[j + k + i] = x + md - y;
      }
  for (int i = 0; i < lim; ++i) b[i] = a[i] % md;
}
void IDFT(int* a) {
  DFT(a), reverse(a + 1, a + lim);
  for (int i = 0; i < lim; ++i) a[i] = (unsigned long long)a[i] * _ilim % md;
}
void init_block() {
  for (int L = 0, R = BL - 1, id = 0; L < n; L = R + 1, R += BL, ++id) {
    R = min(R, n - 1);
    for (int i = L; i <= R; ++i) {
      if (a[i]) sA[id].set(i - L);
      if (b[i]) sB[id].set(i - L);
    }
  }
}
int query(int l, int r, int L, int R) {
  int b0 = (l / BL);
  bitset<BL> X(sA[b0] >> (l & (BL - 1)));
  int b1 = (L / BL);
  L &= BL - 1;
  if (b1 == (R / BL)) {
    bitset<BL> Y(sB[b1] >> L);
    return ((X ^ Y) & prv[r - l]).count();
  } else {
    bitset<BL> Y((sB[b1] >> L) | (sB[b1 + 1] << (BL - L)));
    return ((X ^ Y) & prv[r - l]).count();
  }
}
void work() {
  for (int L = 0, R = BL - 1, id = 1; L < n; L = R + 1, R += BL, ++id) {
    R = min(R, n - 1);
    int len = R - L + 1;
    for (int i = 0; i < lim; ++i) F[i] = 0;
    for (int i = L; i <= R; ++i) F[i - L] = a[i] ? 1 : md - 1;
    DFT(F);
    for (int i = 0; i < lim; ++i) F[i] = (unsigned long long)F[i] * G[i] % md;
    IDFT(F);
    for (int i = 1; i <= q; ++i) {
      int l = QL0[i], r = QR0[i];
      if (l <= L && R <= r) {
        int pos = QL1[i] + (L - l);
        pos = n - 1 - pos;
        ans[i] += (len + md - F[pos]) % md / 2;
      } else if (L <= l && r <= R)
        ans[i] += query(l, r, QL1[i], QR1[i]);
      else if (L <= l && l <= R)
        ans[i] += query(l, R, QL1[i], R - l + QL1[i]);
      else if (L <= r && r <= R)
        ans[i] += query(L, r, QR1[i] + L - r, QR1[i]);
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  init_();
  cin >> a >> b;
  n = max(strlen(a), strlen(b));
  for (int i = 0; i < n; ++i) {
    if (a[i]) a[i] -= '0';
    if (b[i]) b[i] -= '0';
  }
  init_block();
  init(n + BL);
  for (int i = 0; i < n; ++i) G[i] = b[n - i - 1] ? 1 : md - 1;
  DFT(G);
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    int &l0 = QL0[i], &l1 = QL1[i], len;
    cin >> l0 >> l1 >> len;
    QR0[i] = l0 + len - 1, QR1[i] = l1 + len - 1;
  }
  prv[0].set(0);
  for (int i = 1; i < BL; ++i) prv[i] = prv[i - 1], prv[i].set(i);
  work();
  for (int i = 1; i <= q; ++i) cout << ans[i] << '\n';
  return 0;
}
