#include <bits/stdc++.h>
using namespace std;
const int N = 200005, M = 7005, K = 55, mod = 104857601;
char A[N], B[N];
int n, m, q, len, bin[N << 2], f[K][N], Bin[70000], lim;
int p1, p2, lth, id[N], l[K], r[K], ans, inv2;
long long a[N << 2], b[N << 2], fA[N], fB[N];
int getint() {
  char ch;
  while (!isdigit(ch = getchar()))
    ;
  int x = ch - 48;
  while (isdigit(ch = getchar())) x = x * 10 + ch - 48;
  return x;
}
long long getmi(long long a, long long x) {
  long long rt = 1;
  while (x) {
    if (x & 1) rt = rt * a % mod;
    a = a * a % mod, x >>= 1;
  }
  return rt;
}
void FFT(long long a[], int len, int tp) {
  for (int i = 0; i <= len - 1; ++i)
    if (i < bin[i]) swap(a[i], a[bin[i]]);
  for (int i = 1; i < len; i <<= 1) {
    long long wn = getmi(3, (mod - 1) / (i << 1));
    if (tp == -1) wn = getmi(wn, mod - 2);
    for (int j = 0; j < len; j += i << 1) {
      long long w = 1, x, y;
      for (int k = 0; k <= i - 1; ++k) {
        x = a[j + k], y = a[i + j + k] * w % mod, w = w * wn % mod;
        a[j + k] = (x + y) % mod, a[i + j + k] = (x - y + mod) % mod;
      }
    }
  }
  if (tp == -1) {
    long long x = getmi(len, mod - 2);
    for (int i = 0; i <= len - 1; ++i) a[i] = a[i] * x % mod;
  }
}
void build(int id) {
  for (int i = l[id]; i <= r[id]; ++i) a[r[id] - i] = A[i] == '0' ? -1 : 1;
  for (int i = r[id] - l[id] + 1; i <= len - 1; ++i) a[i] = 0;
  FFT(a, len, 1);
  for (int i = 0; i <= len - 1; ++i) a[i] = a[i] * b[i] % mod;
  FFT(a, len, -1);
  for (int i = 0; i <= m - 1; ++i) {
    a[i + r[id] - l[id]] = (a[i + r[id] - l[id]] + mod) % mod;
    f[id][i] = (r[id] - l[id] + 1 - a[i + r[id] - l[id]]) * inv2 % mod;
    f[id][i] = (f[id][i] + mod) % mod;
  }
}
void prepare() {
  inv2 = getmi(2, mod - 2);
  for (len = 1; len <= lim - 1 + m - 1; len <<= 1)
    ;
  for (int i = 0; i <= len - 1; ++i)
    bin[i] = bin[i >> 1] >> 1 | ((i & 1) * (len >> 1));
  for (int i = 0; i <= m - 1; ++i) b[i] = B[i] == '0' ? -1 : 1;
  FFT(b, len, 1);
  for (int i = 0; i <= n - 1; ++i) id[i] = i / lim;
  for (int i = 0; i <= n - 1; ++i) r[id[i]] = i;
  for (int i = n - 1; i >= 0; --i) l[id[i]] = i;
  for (int i = 0; i <= id[n - 1]; ++i) build(i);
}
long long get(long long f[], int s) {
  int x = s >> 5, y = s & 31;
  long long s1 = f[x] >> y, s2 = f[x + 1] & ((1ll << y) - 1);
  return !y ? s1 : s1 | (s2 << (32 - y));
}
int solve_force(int l1, int r1, int l2) {
  long long rt = 0;
  for (int i = l1; i <= r1; ++i) rt += A[i] != B[l2 + i - l1];
  return rt;
}
int solve(int l1, int r1, int l2) {
  int rt = 0;
  for (int i = l1; i <= r1; i += 32) {
    if (i + 32 > r1) {
      rt += solve_force(i, r1, l2 + i - l1);
      break;
    }
    long long x = get(fA, i);
    long long y = get(fB, i - l1 + l2);
    x ^= y, rt += Bin[x >> 16] + Bin[x & 65535];
  }
  return rt;
}
void solve() {
  int ql, qr;
  for (int i = 0; i <= id[n - 1]; ++i)
    if (r[i] >= p1) {
      ans += solve(p1, r[i], p2), ql = i + 1;
      break;
    }
  for (int i = id[n - 1]; i >= 0; --i)
    if (l[i] <= p1 + lth - 1) {
      ans += solve(l[i], p1 + lth - 1, p2 - p1 + l[i]), qr = i - 1;
      break;
    }
  for (int i = ql; i <= qr; ++i) ans += f[i][p2 + l[i] - p1];
  printf("%d\n", ans);
}
int main() {
  scanf("%s", A), n = strlen(A);
  for (int i = 0; i <= n - 1; ++i)
    if (A[i] == '1') {
      int x = i >> 5, y = i & 31;
      fA[x] |= 1ll << y;
    }
  scanf("%s", B), m = strlen(B);
  for (int i = 0; i <= m - 1; ++i)
    if (B[i] == '1') {
      int x = i >> 5, y = i & 31;
      fB[x] |= 1ll << y;
    }
  for (int i = 1; i <= 65535; ++i) Bin[i] = Bin[i ^ (i & -i)] + 1;
  lim = M - 5;
  prepare(), q = getint();
  while (q--) {
    p1 = getint(), p2 = getint(), lth = getint();
    if (id[p1] == id[p1 + lth - 1]) {
      printf("%d\n", solve(p1, p1 + lth - 1, p2));
      continue;
    }
    ans = 0, solve();
  }
  return 0;
}
