#include <bits/stdc++.h>
using namespace std;
namespace fft {
struct num {
  double x, y;
  num() { x = y = 0; }
  num(double x, double y) : x(x), y(y) {}
};
inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); }
inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); }
inline num operator*(num a, num b) {
  return num(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
}
inline num conj(num a) { return num(a.x, -a.y); }
int base = 1;
vector<num> roots = {{0, 0}, {1, 0}};
vector<int> rev = {0, 1};
const double PI = acosl(-1.0);
void ensure_base(int nbase) {
  if (nbase <= base) {
    return;
  }
  rev.resize(1 << nbase);
  for (int i = 0; i < (1 << nbase); i++) {
    rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));
  }
  roots.resize(1 << nbase);
  while (base < nbase) {
    double angle = 2 * PI / (1 << (base + 1));
    for (int i = 1 << (base - 1); i < (1 << base); i++) {
      roots[i << 1] = roots[i];
      double angle_i = angle * (2 * i + 1 - (1 << base));
      roots[(i << 1) + 1] = num(cos(angle_i), sin(angle_i));
    }
    base++;
  }
}
void fft(vector<num> &a, int n = -1) {
  if (n == -1) {
    n = a.size();
  }
  assert((n & (n - 1)) == 0);
  int zeros = __builtin_ctz(n);
  ensure_base(zeros);
  int shift = base - zeros;
  for (int i = 0; i < n; i++) {
    if (i < (rev[i] >> shift)) {
      swap(a[i], a[rev[i] >> shift]);
    }
  }
  for (int k = 1; k < n; k <<= 1) {
    for (int i = 0; i < n; i += 2 * k) {
      for (int j = 0; j < k; j++) {
        num z = a[i + j + k] * roots[j + k];
        a[i + j + k] = a[i + j] - z;
        a[i + j] = a[i + j] + z;
      }
    }
  }
}
vector<num> fa, fb;
vector<int> multiply(vector<int> &a, vector<int> &b) {
  int need = a.size() + b.size() - 1;
  int nbase = 0;
  while ((1 << nbase) < need) nbase++;
  ensure_base(nbase);
  int sz = 1 << nbase;
  if (sz > (int)fa.size()) {
    fa.resize(sz);
  }
  for (int i = 0; i < sz; i++) {
    int x = (i < (int)a.size() ? a[i] : 0);
    int y = (i < (int)b.size() ? b[i] : 0);
    fa[i] = num(x, y);
  }
  fft(fa, sz);
  num r(0, -0.25 / sz);
  for (int i = 0; i <= (sz >> 1); i++) {
    int j = (sz - i) & (sz - 1);
    num z = (fa[j] * fa[j] - conj(fa[i] * fa[i])) * r;
    if (i != j) {
      fa[j] = (fa[i] * fa[i] - conj(fa[j] * fa[j])) * r;
    }
    fa[i] = z;
  }
  fft(fa, sz);
  vector<int> res(need);
  for (int i = 0; i < need; i++) {
    res[i] = fa[i].x + (fa[i].x > 0 ? 0.5 : -0.5);
  }
  return res;
}
};  // namespace fft
const int N = 2e5 + 5;
const int K = 7000;
const int MASK = (1 << 16) - 1;
int n, m, q;
char a[N], b[N];
int cnt[N];
unsigned a1[32][N >> 5], a2[32][N >> 5];
vector<int> mul[N / K + 5];
int get(int l, int r, int len) {
  int ans = 0;
  while (len >= 32 and l % K != 1 and l % K and
         ((l + 32) % K > l % K or (l + 32) % K == 0)) {
    int w1 = (l - 1) & 31;
    int w2 = (r - 1) & 31;
    int x = (l - 1) >> 5;
    int y = (r - 1) >> 5;
    unsigned mask = a1[w1][x] ^ a2[w2][y];
    ans += cnt[mask & MASK] + cnt[mask >> 16];
    l += 32;
    r += 32;
    len -= 32;
  }
  while (len and l % K != 1) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  while (len >= K) {
    int id = (l - 1) / K;
    int i = m - 1 - (r - 1);
    ans += (K - mul[id][i]) / 2;
    l += K;
    r += K;
    len -= K;
  }
  while (len >= 32) {
    int w1 = (l - 1) & 31;
    int w2 = (r - 1) & 31;
    int x = (l - 1) >> 5;
    int y = (r - 1) >> 5;
    unsigned mask = a1[w1][x] ^ a2[w2][y];
    ans += cnt[mask & MASK] + cnt[mask >> 16];
    l += 32;
    r += 32;
    len -= 32;
  }
  while (len) {
    ans += a[l] != b[r];
    l++;
    r++;
    len--;
  }
  return ans;
}
int main() {
  for (int i = 1; i < (1 << 16); i++) cnt[i] = cnt[i - (i & -i)] + 1;
  scanf("%s %s", a + 1, b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  for (int j = 0; j < 32; j++) {
    for (int i = 0; i + j < n; i++)
      if (a[i + j + 1] == '1') a1[j][i >> 5] |= 1 << (i & 31);
  }
  for (int j = 0; j < 32; j++) {
    for (int i = 0; i + j < m; i++)
      if (b[i + j + 1] == '1') a2[j][i >> 5] |= 1 << (i & 31);
  }
  auto upd = [&](char s[N], int n) {
    for (int i = 1; i <= n; i++) {
      if (s[i] == '1')
        s[i] = 1;
      else
        s[i] = -1;
    }
  };
  upd(a, n);
  upd(b, m);
  auto getVec = [&](char s[N], int l, int r) {
    vector<int> v;
    for (int i = l; i <= r; i++) {
      v.push_back(s[i]);
    }
    return v;
  };
  vector<int> vb = getVec(b, 1, m);
  reverse(vb.begin(), vb.end());
  for (int i = 1; i <= n; i += K) {
    int id = (i - 1) / K;
    int end = min(n, i + K - 1);
    vector<int> va = getVec(a, i, end);
    mul[id] = fft ::multiply(va, vb);
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int l, r, len;
    scanf("%d %d %d", &l, &r, &len);
    l++;
    r++;
    int res = get(l, r, len);
    printf("%d\n", res);
  }
  return 0;
}
